@@ -23,7 +23,14 @@ class Connections(Plugin):
23
23
'number of disabled' ,
24
24
'00CCCC' )
25
25
]
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
+ ]
26
32
Max_connections = None
33
+
27
34
query_agent = "select count(*) from pg_catalog.pg_stat_activity where state = '{0}';"
28
35
query_agent_total = "select count(*) from pg_catalog.pg_stat_activity where state is not null ;"
29
36
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):
74
81
self .Max_connections = result [0 ][0 ]
75
82
zbx .send ('pgsql.connections[max_connections]' , int (self .Max_connections ))
76
83
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
+
77
89
def items (self , template ):
78
90
result = template .item ({
79
91
'name' : 'PostgreSQL: number of total connections' ,
@@ -97,6 +109,11 @@ def items(self, template):
97
109
'key' : self .right_type (self .key , item [1 ]),
98
110
'delay' : self .plugin_config ('interval' )
99
111
})
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
+ })
100
117
return result
101
118
102
119
def graphs (self , template ):
@@ -118,6 +135,10 @@ def graphs(self, template):
118
135
'key' : self .right_type (self .key , "max_connections" ),
119
136
'color' : '00BB00'
120
137
})
138
+ items .append ({
139
+ 'key' : self .right_type (self .Item_ppid_children [0 ][0 ]),
140
+ 'color' : '0BB000'
141
+ })
121
142
graph = {'name' : 'PostgreSQL connections' , 'items' : items }
122
143
return template .graph (graph )
123
144
0 commit comments