2
2
3
3
from mamonsu .plugins .pgsql .plugin import PgsqlPlugin as Plugin
4
4
from distutils .version import LooseVersion
5
+ import mamonsu .lib .platform as platform
5
6
from .pool import Pooler
6
7
7
8
@@ -23,7 +24,14 @@ class Connections(Plugin):
23
24
'number of disabled' ,
24
25
'00CCCC' )
25
26
]
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
+ ]
26
33
Max_connections = None
34
+
27
35
query_agent = "select count(*) from pg_catalog.pg_stat_activity where state = '{0}';"
28
36
query_agent_total = "select count(*) from pg_catalog.pg_stat_activity where state is not null ;"
29
37
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):
74
82
self .Max_connections = result [0 ][0 ]
75
83
zbx .send ('pgsql.connections[max_connections]' , int (self .Max_connections ))
76
84
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
+
77
91
def items (self , template ):
78
92
result = template .item ({
79
93
'name' : 'PostgreSQL: number of total connections' ,
@@ -97,6 +111,11 @@ def items(self, template):
97
111
'key' : self .right_type (self .key , item [1 ]),
98
112
'delay' : self .plugin_config ('interval' )
99
113
})
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
+ })
100
119
return result
101
120
102
121
def graphs (self , template ):
@@ -118,6 +137,10 @@ def graphs(self, template):
118
137
'key' : self .right_type (self .key , "max_connections" ),
119
138
'color' : '00BB00'
120
139
})
140
+ items .append ({
141
+ 'key' : self .right_type (self .Item_ppid_children [0 ][0 ]),
142
+ 'color' : '0BB000'
143
+ })
121
144
graph = {'name' : 'PostgreSQL connections' , 'items' : items }
122
145
return template .graph (graph )
123
146
0 commit comments