@@ -20,21 +20,6 @@ class Databases(Plugin):
20
20
query_agent_discovery = "SELECT json_build_object ('data',json_agg(json_build_object('{#DATABASE}',d.datname)))" \
21
21
" FROM pg_database d WHERE NOT datistemplate AND datallowconn AND datname!='postgres';"
22
22
23
- # dictionary to keep all queries in one container
24
- SQL = {"pgsql.database.discovery{0}" : "SELECT json_build_object "
25
- "('data',json_agg(json_build_object('{#DATABASE}',d.datname)))" \
26
- " FROM pg_database d WHERE NOT datistemplate AND datallowconn "
27
- "AND datname!='postgres';" ,
28
- "pgsql.database.size{0}" : "select pg_database_size(datname::text) from pg_catalog.pg_database where" \
29
- " datistemplate = false and datname = :'p1'" ,
30
- "pgsql.database.max_age{0}" : "select age(datfrozenxid) from pg_catalog.pg_database "
31
- "where datistemplate = false " \
32
- "and datname = :'p1'" ,
33
- "pgsql.database.bloating_tables{0}" : "select count(*) from pg_catalog.pg_stat_all_tables where " \
34
- "(n_dead_tup/(n_live_tup+n_dead_tup)::float8) > {0} and " \
35
- "(n_live_tup+n_dead_tup) > {1}" ,
36
- "pgsql.autovacumm.count{0}" : Pooler .SQL ['count_autovacuum' ][0 ]
37
- }
38
23
key_db_discovery = "pgsql.database.discovery{0}"
39
24
key_db_size = "pgsql.database.size{0}"
40
25
key_db_age = "pgsql.database.max_age{0}"
@@ -72,7 +57,7 @@ def items(self, template):
72
57
return template .item ({
73
58
'name' : 'PostgreSQL: count of autovacuum workers' ,
74
59
'key' : self .right_type (self .key_autovacumm ),
75
- 'delay' : self .plugin_config ('interval' )
60
+ 'delay' : self .plugin_config ('interval' )
76
61
})
77
62
78
63
def discovery_rules (self , template ):
@@ -86,13 +71,13 @@ def discovery_rules(self, template):
86
71
'name' : 'Database {#DATABASE}: size' ,
87
72
'units' : Plugin .UNITS .bytes ,
88
73
'value_type' : Plugin .VALUE_TYPE .numeric_unsigned ,
89
- 'delay' : self .plugin_config ('interval' )},
74
+ 'delay' : self .plugin_config ('interval' )},
90
75
{'key' : self .right_type (self .key_db_age , var_discovery = "{#DATABASE}," ),
91
76
'name' : 'Max age (datfrozenxid) in: {#DATABASE}' ,
92
- 'delay' : self .plugin_config ('interval' )},
77
+ 'delay' : self .plugin_config ('interval' )},
93
78
{'key' : self .right_type (self .key_db_bloating_tables , var_discovery = "{#DATABASE}," ),
94
79
'name' : 'Count of bloating tables in database: {#DATABASE}' ,
95
- 'delay' : self .plugin_config ('interval' )}
80
+ 'delay' : self .plugin_config ('interval' )}
96
81
]
97
82
graphs = [
98
83
{
@@ -131,6 +116,6 @@ def keys_and_queries(self, template_zabbix):
131
116
result .append ('{0},echo "{1}" | $3 $2 -v p1="$1"' .format (self .key_db_age .format ("[*]" ), self .query_age ))
132
117
result .append (
133
118
'{0},$3 $2 -d "$1" -c "{1}"' .format (self .key_db_bloating_tables .format ("[*]" ),
134
- self .query_bloating_tables .format (self .plugin_config ('bloat_scale' ),
135
- self .plugin_config ('min_rows' ))))
119
+ self .query_bloating_tables .format (self .plugin_config ('bloat_scale' ),
120
+ self .plugin_config ('min_rows' ))))
136
121
return template_zabbix .key_and_query (result )
0 commit comments