Skip to content

Commit

Permalink
chore: add metrics for pending to process events
Browse files Browse the repository at this point in the history
  • Loading branch information
cquintana92 committed May 24, 2024
1 parent 5f190d4 commit 478ce74
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from time import sleep
from typing import List, Dict

import arrow
import newrelic.agent

from app.db import Session
Expand Down Expand Up @@ -104,12 +105,27 @@ def log_pending_to_process_events():
)


@newrelic.agent.background_task()
def log_not_finished_processing_events():
since = arrow.now().shift(minutes=-10).datetime
r = Session.execute(
"select count(*) from sync_event WHERE taken_time < :since ;", {"since": since}
)
events_pending = list(r)[0][0]

LOG.d("number of events not finished processing %s", events_pending)
newrelic.agent.record_custom_metric(
"Custom/sync_events_not_finished_processing", events_pending
)


if __name__ == "__main__":
exporter = MetricExporter(get_newrelic_license())
while True:
log_postfix_metrics()
log_nb_db_connection()
log_pending_to_process_events()
log_not_finished_processing_events()
Session.close()

exporter.run()
Expand Down

0 comments on commit 478ce74

Please sign in to comment.