@@ -37,6 +37,13 @@ class Databases(Plugin):
3737 AND l.relation IS NULL;
3838 """
3939
40+ # PG 14+ queries
41+ query_sessions = """
42+ SELECT {0}
43+ FROM pg_catalog.pg_stat_database
44+ WHERE datname = '{1}';
45+ """
46+
4047 # queries for zabbix agent
4148 query_agent_discovery = """
4249 SELECT json_build_object ('data',json_agg(json_build_object('{#DATABASE}',d.datname)))
@@ -53,6 +60,15 @@ class Databases(Plugin):
5360 key_autovacumm = "pgsql.autovacumm.count{0}"
5461 key_invalid_indexes = "pgsql.database.invalid_indexes{0}"
5562
63+ # PG 14+ keys
64+ key_db_sessions = [("sessions" , "pgsql.database.sessions[{0}]" , "Total Number of Sessions" , Plugin .UNITS .none , Plugin .VALUE_TYPE .numeric_unsigned ),
65+ ("sessions_abandoned" , "pgsql.database.sessions_abandoned[{0}]" , "Client Lost Connection Terminated Sessions" , Plugin .UNITS .none , Plugin .VALUE_TYPE .numeric_unsigned ),
66+ ("sessions_fatal" , "pgsql.database.sessions_fatal[{0}]" , "Fatal Errors Terminated Sessions" , Plugin .UNITS .none , Plugin .VALUE_TYPE .numeric_unsigned ),
67+ ("sessions_killed" , "pgsql.database.sessions_killed[{0}]" , "Operator Intervention Terminated Sessions" , Plugin .UNITS .none , Plugin .VALUE_TYPE .numeric_unsigned ),
68+ ("session_time" , "pgsql.database.session_time[{0}]" , "Time Spent by Sessions" , Plugin .UNITS .ms , Plugin .VALUE_TYPE .numeric_float ),
69+ ("active_time" , "pgsql.database.active_time[{0}]" , "Time Spent Executing SQL Statements" , Plugin .UNITS .ms , Plugin .VALUE_TYPE .numeric_float ),
70+ ("idle_in_transaction_time" , "pgsql.database.idle_in_transaction_time[{0}]" , "Time Spent Idling While in a Transaction" , Plugin .UNITS .ms , Plugin .VALUE_TYPE .numeric_float )]
71+
5672 DEFAULT_CONFIG = {
5773 "min_rows" : str (50 ),
5874 "bloat_scale" : str (0.2 )
@@ -78,6 +94,12 @@ def run(self, zbx):
7894 zbx .send ("pgsql.database.bloating_tables[{0}]" .format (info [0 ]), int (bloat_count ))
7995 invalid_indexes_count = Pooler .query (self .query_invalid_indexes , info [0 ])[0 ][0 ]
8096 zbx .send ("pgsql.database.invalid_indexes[{0}]" .format (info [0 ]), int (invalid_indexes_count ))
97+
98+ if Pooler .server_version_greater ("14" ):
99+ for session_item in self .key_db_sessions :
100+ session_result = Pooler .query (self .query_sessions .format (session_item [0 ], info [0 ]), info [0 ])[0 ][0 ]
101+ zbx .send (session_item [1 ].format (info [0 ]), int (session_result ))
102+
81103 zbx .send ("pgsql.database.discovery[]" , zbx .json ({"data" : dbs }))
82104 del dbs , bloat_count , invalid_indexes_count
83105
@@ -151,6 +173,17 @@ def discovery_rules(self, template, dashboard=False):
151173 "name" : "PostgreSQL Databases: Count of Invalid Indexes in {#DATABASE}" ,
152174 "delay" : self .plugin_config ("interval" )}
153175 ]
176+
177+ if Pooler .server_version_greater ("14" ):
178+ for session_item in self .key_db_sessions :
179+ items .append ({
180+ "key" : self .right_type (session_item [1 ], var_discovery = "{#DATABASE}," ),
181+ "name" : "PostgreSQL Databases {{#DATABASE}}: {0}" .format (session_item [2 ]),
182+ "units" : session_item [3 ],
183+ "value_type" : session_item [4 ],
184+ "delay" : self .plugin_config ("interval" )
185+ })
186+
154187 graphs = [{
155188 "name" : "PostgreSQL Databases: {#DATABASE} size" ,
156189 "type" : 1 ,
0 commit comments