@@ -10,20 +10,21 @@ class Oldest(Plugin):
10
10
OldestXidSql = "select greatest(max(age(backend_xmin)), max(age(backend_xid))) from pg_catalog.pg_stat_activity;"
11
11
12
12
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%%'; "
17
13
18
14
# OldestQuery = " SELECT query FROM pg_catalog.pg_stat_activity WHERE extract(epoch FROM (now() - query_start))=(SELECT " \
19
15
# "extract(epoch from max(now() - query_start)) FROM pg_catalog.pg_stat_activity) and pid not " \
20
16
# "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
+ """
23
24
24
25
DEFAULT_CONFIG = {
25
26
'max_xid_age' : str (5000 * 60 * 60 ),
26
- 'max_query_time ' : str (5 * 60 * 60 )
27
+ 'max_transaction_time ' : str (5 * 60 * 60 )
27
28
}
28
29
29
30
def run (self , zbx ):
@@ -35,13 +36,13 @@ def run(self, zbx):
35
36
query = Pooler .query (self .OldestQuerySql )[0 ][0 ]
36
37
37
38
zbx .send ('pgsql.oldest[xid_age]' , xid )
38
- zbx .send ('pgsql.oldest[query_time ]' , query )
39
+ zbx .send ('pgsql.oldest[transaction_time ]' , query )
39
40
40
41
def graphs (self , template ):
41
42
result = template .graph ({
42
- 'name' : 'PostgreSQL oldest query running time' ,
43
+ 'name' : 'PostgreSQL oldest transaction running time' ,
43
44
'items' : [{
44
- 'key' : self .right_type (self .key , 'query_time ' ),
45
+ 'key' : self .right_type (self .key , 'transaction_time ' ),
45
46
'color' : '00CC00'
46
47
}]
47
48
})
@@ -61,8 +62,9 @@ def items(self, template):
61
62
'delay' : self .plugin_config ('interval' ),
62
63
'value_type' : Plugin .VALUE_TYPE .numeric_unsigned
63
64
}) + 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' ,
66
68
'delay' : self .plugin_config ('interval' ),
67
69
'units' : Plugin .UNITS .s
68
70
})
@@ -74,8 +76,8 @@ def triggers(self, template):
74
76
'.last()}>' + self .plugin_config ('max_xid_age' )
75
77
}) + template .trigger ({
76
78
'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 ' )
79
81
})
80
82
81
83
def keys_and_queries (self , template_zabbix ):
0 commit comments