22
33from mamonsu .plugins .pgsql .plugin import PgsqlPlugin as Plugin
44from distutils .version import LooseVersion
5+ import mamonsu .lib .platform as platform
56from .pool import Pooler
67
78
@@ -23,7 +24,14 @@ class Connections(Plugin):
2324 'number of disabled' ,
2425 '00CCCC' )
2526 ]
27+ # ( key, name, graph)
28+ Item_ppid_children = [
29+ ('pgsql.count_all_pids{0}' ,
30+ 'Number of PostgreSQL parent pid children' ,
31+ ('PostgreSQL: count children of PostgreSQL parent pid' , 'BBB000' , 0 )),
32+ ]
2633 Max_connections = None
34+
2735 query_agent = "select count(*) from pg_catalog.pg_stat_activity where state = '{0}';"
2836 query_agent_total = "select count(*) from pg_catalog.pg_stat_activity where state is not null ;"
2937 query_agent_waiting_new_v = "select count(*) from pg_catalog.pg_stat_activity where state is not null and " \
@@ -74,6 +82,12 @@ def run(self, zbx):
7482 self .Max_connections = result [0 ][0 ]
7583 zbx .send ('pgsql.connections[max_connections]' , int (self .Max_connections ))
7684
85+ # get number of child pids of ppid
86+ if platform .LINUX :
87+ num_of_children_pids = self .get_num_of_children_pids ()
88+ key = self .Item_ppid_children [0 ][0 ].format ('[]' )
89+ zbx .send (key , num_of_children_pids + 1 )
90+
7791 def items (self , template ):
7892 result = template .item ({
7993 'name' : 'PostgreSQL: number of total connections' ,
@@ -97,6 +111,11 @@ def items(self, template):
97111 'key' : self .right_type (self .key , item [1 ]),
98112 'delay' : self .plugin_config ('interval' )
99113 })
114+ result += template .item ({
115+ 'name' : 'PostgreSQL: number of child pids' ,
116+ 'key' : self .right_type (self .Item_ppid_children [0 ][0 ]),
117+ 'delay' : self .plugin_config ('interval' )
118+ })
100119 return result
101120
102121 def graphs (self , template ):
@@ -118,6 +137,10 @@ def graphs(self, template):
118137 'key' : self .right_type (self .key , "max_connections" ),
119138 'color' : '00BB00'
120139 })
140+ items .append ({
141+ 'key' : self .right_type (self .Item_ppid_children [0 ][0 ]),
142+ 'color' : '0BB000'
143+ })
121144 graph = {'name' : 'PostgreSQL connections' , 'items' : items }
122145 return template .graph (graph )
123146
0 commit comments