@@ -23,7 +23,14 @@ class Connections(Plugin):
2323 'number of disabled' ,
2424 '00CCCC' )
2525 ]
26+ # ( key, name, graph)
27+ Item_ppid_children = [
28+ ('pgsql.count_all_pids{0}' ,
29+ 'Number of PostgreSQL parent pid children' ,
30+ ('PostgreSQL: count children of PostgreSQL parent pid' , 'BBB000' , 0 )),
31+ ]
2632 Max_connections = None
33+
2734 query_agent = "select count(*) from pg_catalog.pg_stat_activity where state = '{0}';"
2835 query_agent_total = "select count(*) from pg_catalog.pg_stat_activity where state is not null ;"
2936 query_agent_waiting_new_v = "select count(*) from pg_catalog.pg_stat_activity where state is not null and " \
@@ -74,6 +81,11 @@ def run(self, zbx):
7481 self .Max_connections = result [0 ][0 ]
7582 zbx .send ('pgsql.connections[max_connections]' , int (self .Max_connections ))
7683
84+ # get number of child pids of ppid
85+ num_of_children_pids = self .get_num_of_children_pids ()
86+ key = self .Item_ppid_children [0 ][0 ].format ('[]' )
87+ zbx .send (key , num_of_children_pids + 1 )
88+
7789 def items (self , template ):
7890 result = template .item ({
7991 'name' : 'PostgreSQL: number of total connections' ,
@@ -97,6 +109,11 @@ def items(self, template):
97109 'key' : self .right_type (self .key , item [1 ]),
98110 'delay' : self .plugin_config ('interval' )
99111 })
112+ result += template .item ({
113+ 'name' : 'PostgreSQL: number of child pids' ,
114+ 'key' : self .right_type (self .Item_ppid_children [0 ][0 ]),
115+ 'delay' : self .plugin_config ('interval' )
116+ })
100117 return result
101118
102119 def graphs (self , template ):
@@ -118,6 +135,10 @@ def graphs(self, template):
118135 'key' : self .right_type (self .key , "max_connections" ),
119136 'color' : '00BB00'
120137 })
138+ items .append ({
139+ 'key' : self .right_type (self .Item_ppid_children [0 ][0 ]),
140+ 'color' : '0BB000'
141+ })
121142 graph = {'name' : 'PostgreSQL connections' , 'items' : items }
122143 return template .graph (graph )
123144
0 commit comments