1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

optimize awx-manage callback_stats for larger datasets

to monitor this historically, we'd probably need to introduce a new
index on the modified column of all our event types
This commit is contained in:
Ryan Petrello 2020-01-22 16:51:37 -05:00
parent c983b6a755
commit f9af5e8959
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -9,6 +9,13 @@ class Command(BaseCommand):
def handle(self, *args, **options):
with connection.cursor() as cursor:
start = {}
for relation in (
'main_jobevent', 'main_inventoryupdateevent',
'main_projectupdateevent', 'main_adhoccommandevent'
):
cursor.execute(f"SELECT MAX(id) FROM {relation};")
start[relation] = cursor.fetchone()[0] or 0
clear = False
while True:
lines = []
@ -17,19 +24,15 @@ class Command(BaseCommand):
'main_projectupdateevent', 'main_adhoccommandevent'
):
lines.append(relation)
for label, interval in (
('last minute: ', '1 minute'),
('last 5 minutes:', '5 minutes'),
('last hour: ', '1 hour'),
):
cursor.execute(
f"SELECT MAX(id) - MIN(id) FROM {relation} WHERE modified > now() - '{interval}'::interval;"
)
events = cursor.fetchone()[0] or 0
lines.append(f'{label} {events}')
minimum = start[relation]
cursor.execute(
f"SELECT MAX(id) - MIN(id) FROM {relation} WHERE id > {minimum} AND modified > now() - '1 minute'::interval;"
)
events = cursor.fetchone()[0] or 0
lines.append(f'↳ last minute {events}')
lines.append('')
if clear:
for i in range(20):
for i in range(12):
sys.stdout.write('\x1b[1A\x1b[2K')
for l in lines:
print(l)