@@ -37,6 +37,13 @@ class Databases(Plugin):
37
37
AND l.relation IS NULL;
38
38
"""
39
39
40
+ # PG 14+ queries
41
+ query_sessions = """
42
+ SELECT {0}
43
+ FROM pg_catalog.pg_stat_database
44
+ WHERE datname = '{1}';
45
+ """
46
+
40
47
# queries for zabbix agent
41
48
query_agent_discovery = """
42
49
SELECT json_build_object ('data',json_agg(json_build_object('{#DATABASE}',d.datname)))
@@ -53,6 +60,15 @@ class Databases(Plugin):
53
60
key_autovacumm = "pgsql.autovacumm.count{0}"
54
61
key_invalid_indexes = "pgsql.database.invalid_indexes{0}"
55
62
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
+
56
72
DEFAULT_CONFIG = {
57
73
"min_rows" : str (50 ),
58
74
"bloat_scale" : str (0.2 )
@@ -78,6 +94,12 @@ def run(self, zbx):
78
94
zbx .send ("pgsql.database.bloating_tables[{0}]" .format (info [0 ]), int (bloat_count ))
79
95
invalid_indexes_count = Pooler .query (self .query_invalid_indexes , info [0 ])[0 ][0 ]
80
96
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
+
81
103
zbx .send ("pgsql.database.discovery[]" , zbx .json ({"data" : dbs }))
82
104
del dbs , bloat_count , invalid_indexes_count
83
105
@@ -151,6 +173,17 @@ def discovery_rules(self, template, dashboard=False):
151
173
"name" : "PostgreSQL Databases: Count of Invalid Indexes in {#DATABASE}" ,
152
174
"delay" : self .plugin_config ("interval" )}
153
175
]
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
+
154
187
graphs = [{
155
188
"name" : "PostgreSQL Databases: {#DATABASE} size" ,
156
189
"type" : 1 ,
0 commit comments