mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
Add monitoring for app connections to the db (#2235)
This commit is contained in:
parent
20c1145a1d
commit
df4c52815b
2 changed files with 18 additions and 1 deletions
|
@ -72,7 +72,9 @@ class PostgresEventSource(EventSource):
|
|||
Session.close() # Ensure we get a new connection and we don't leave a dangling tx
|
||||
|
||||
def __connect(self):
|
||||
self.__connection = psycopg2.connect(self.__connection_string)
|
||||
self.__connection = psycopg2.connect(
|
||||
self.__connection_string, application_name="sl-event-listen"
|
||||
)
|
||||
|
||||
from app.db import Session
|
||||
|
||||
|
|
|
@ -94,6 +94,20 @@ def log_nb_db_connection():
|
|||
newrelic.agent.record_custom_metric("Custom/nb_db_connections", nb_connection)
|
||||
|
||||
|
||||
@newrelic.agent.background_task()
|
||||
def log_nb_db_connection_by_app_name():
|
||||
# get the number of connections to the DB
|
||||
rows = Session.execute(
|
||||
"SELECT application_name, count(datid) FROM pg_stat_activity group by application_name"
|
||||
)
|
||||
for row in rows:
|
||||
if row[0].find("sl-") == 0:
|
||||
LOG.d("number of db connections for app %s = %s", row[0], row[1])
|
||||
newrelic.agent.record_custom_metric(
|
||||
f"Custom/nb_db_app_connection/{row[0]}", row[1]
|
||||
)
|
||||
|
||||
|
||||
@newrelic.agent.background_task()
|
||||
def log_pending_to_process_events():
|
||||
r = Session.execute("select count(*) from sync_event WHERE taken_time IS NULL;")
|
||||
|
@ -148,6 +162,7 @@ if __name__ == "__main__":
|
|||
log_pending_to_process_events()
|
||||
log_events_pending_dead_letter()
|
||||
log_failed_events()
|
||||
log_nb_db_connection_by_app_name()
|
||||
Session.close()
|
||||
|
||||
exporter.run()
|
||||
|
|
Loading…
Reference in a new issue