@@ -10,20 +10,21 @@ class Oldest(Plugin):
1010 OldestXidSql = "select greatest(max(age(backend_xmin)), max(age(backend_xid))) from pg_catalog.pg_stat_activity;"
1111
1212 OldestXidSql_bootstrap = "select public.mamonsu_get_oldest_xid();"
13- OldestQuerySql = "select case when extract(epoch from max(now() - xact_start)) is not null then extract(epoch" \
14- " from max(now() - xact_start)) else 0 end from pg_catalog.pg_stat_activity where pid not in " \
15- "(select pid from pg_stat_replication) AND pid <> pg_backend_pid() " \
16- "AND query not ilike '%%VACUUM%%'; "
1713
1814 # OldestQuery = " SELECT query FROM pg_catalog.pg_stat_activity WHERE extract(epoch FROM (now() - query_start))=(SELECT " \
1915 # "extract(epoch from max(now() - query_start)) FROM pg_catalog.pg_stat_activity) and pid not " \
2016 # "in (select pid from pg_stat_replication) AND pid <> pg_backend_pid() AND query not ilike '%%VACUUM%%';"
21-
22- OldestQuerySql_bootstrap = "select public.mamonsu_get_oldest_query();"
17+ OldestQuerySql = "SELECT CASE WHEN extract(epoch from max(now() - xact_start)) IS NOT NULL AND extract(epoch" \
18+ " from max(now() - xact_start))>0 THEN extract(epoch from max(now() - xact_start)) ELSE 0 END FROM " \
19+ "pg_catalog.pg_stat_activity WHERE pid NOT IN (SELECT pid FROM pg_stat_replication) AND " \
20+ "pid <> pg_backend_pid(); "
21+ OldestQuerySql_bootstrap = """
22+ select public.mamonsu_get_oldest_query();
23+ """
2324
2425 DEFAULT_CONFIG = {
2526 'max_xid_age' : str (5000 * 60 * 60 ),
26- 'max_query_time ' : str (5 * 60 * 60 )
27+ 'max_transaction_time ' : str (5 * 60 * 60 )
2728 }
2829
2930 def run (self , zbx ):
@@ -35,13 +36,13 @@ def run(self, zbx):
3536 query = Pooler .query (self .OldestQuerySql )[0 ][0 ]
3637
3738 zbx .send ('pgsql.oldest[xid_age]' , xid )
38- zbx .send ('pgsql.oldest[query_time ]' , query )
39+ zbx .send ('pgsql.oldest[transaction_time ]' , query )
3940
4041 def graphs (self , template ):
4142 result = template .graph ({
42- 'name' : 'PostgreSQL oldest query running time' ,
43+ 'name' : 'PostgreSQL oldest transaction running time' ,
4344 'items' : [{
44- 'key' : self .right_type (self .key , 'query_time ' ),
45+ 'key' : self .right_type (self .key , 'transaction_time ' ),
4546 'color' : '00CC00'
4647 }]
4748 })
@@ -61,8 +62,9 @@ def items(self, template):
6162 'delay' : self .plugin_config ('interval' ),
6263 'value_type' : Plugin .VALUE_TYPE .numeric_unsigned
6364 }) + template .item ({
64- 'key' : self .right_type (self .key , 'query_time' ),
65- 'name' : 'PostgreSQL: oldest query running time in sec' ,
65+
66+ 'key' : self .right_type (self .key , 'transaction_time' ),
67+ 'name' : 'PostgreSQL: oldest transaction running time in sec' ,
6668 'delay' : self .plugin_config ('interval' ),
6769 'units' : Plugin .UNITS .s
6870 })
@@ -74,8 +76,8 @@ def triggers(self, template):
7476 '.last()}>' + self .plugin_config ('max_xid_age' )
7577 }) + template .trigger ({
7678 'name' : 'PostgreSQL query running is too old on {HOSTNAME}' ,
77- 'expression' : '{#TEMPLATE:' + self .right_type (self .key , 'query_time ' ) +
78- '.last()}>' + self .plugin_config ('max_query_time ' )
79+ 'expression' : '{#TEMPLATE:' + self .right_type (self .key , 'transaction_time ' ) +
80+ '.last()}>' + self .plugin_config ('max_transaction_time ' )
7981 })
8082
8183 def keys_and_queries (self , template_zabbix ):
0 commit comments