mirror of
https://github.com/ansible/awx.git
synced 2026-02-13 17:24:45 -03:30
additionaly, optimize away several per-event host lookups and changed/failed propagation lookups we've always performed these (fairly expensive) queries *on every event save* - if you're processing tens of thousands of events in short bursts, this is way too slow this commit also introduces a new command for profiling the insertion rate of events, `awx-manage callback_stats` see: https://github.com/ansible/awx/issues/5514
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import time
|
|
import sys
|
|
|
|
from django.db import connection
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
def handle(self, *args, **options):
|
|
with connection.cursor() as cursor:
|
|
clear = False
|
|
while True:
|
|
lines = []
|
|
for relation in (
|
|
'main_jobevent', 'main_inventoryupdateevent',
|
|
'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}')
|
|
lines.append('')
|
|
if clear:
|
|
for i in range(20):
|
|
sys.stdout.write('\x1b[1A\x1b[2K')
|
|
for l in lines:
|
|
print(l)
|
|
clear = True
|
|
time.sleep(.25)
|