Skip to content

Commit eacf984

Browse files
committed
fix: remove num connections via ps item
1 parent 490f937 commit eacf984

File tree

2 files changed

+0
-44
lines changed

2 files changed

+0
-44
lines changed

mamonsu/plugins/pgsql/connections.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin
44
from distutils.version import LooseVersion
5-
import mamonsu.lib.platform as platform
65
from .pool import Pooler
76

87

@@ -24,12 +23,6 @@ class Connections(Plugin):
2423
'number of disabled',
2524
'00CCCC')
2625
]
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-
]
3326
Max_connections = None
3427

3528
query_agent = "select count(*) from pg_catalog.pg_stat_activity where state = '{0}';"
@@ -82,12 +75,6 @@ def run(self, zbx):
8275
self.Max_connections = result[0][0]
8376
zbx.send('pgsql.connections[max_connections]', int(self.Max_connections))
8477

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-
9178
def items(self, template):
9279
result = template.item({
9380
'name': 'PostgreSQL: number of total connections',
@@ -111,11 +98,6 @@ def items(self, template):
11198
'key': self.right_type(self.key, item[1]),
11299
'delay': self.plugin_config('interval')
113100
})
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-
})
119101
return result
120102

121103
def graphs(self, template):
@@ -137,10 +119,6 @@ def graphs(self, template):
137119
'key': self.right_type(self.key, "max_connections"),
138120
'color': '00BB00'
139121
})
140-
items.append({
141-
'key': self.right_type(self.Item_ppid_children[0][0]),
142-
'color': '0BB000'
143-
})
144122
graph = {'name': 'PostgreSQL connections', 'items': items}
145123
return template.graph(graph)
146124

mamonsu/plugins/pgsql/plugin.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,6 @@ def check(self, extension):
3434

3535
return self._ext_installed
3636

37-
@staticmethod
38-
def get_num_of_children_pids():
39-
result = Pooler.query("SELECT pg_backend_pid();")
40-
child_pid = result[0][0]
41-
try:
42-
parent_pid = subprocess.check_output(['ps', '-oppid', '--no-headers', '--pid', str(child_pid)],
43-
stderr=subprocess.PIPE, encoding='utf8')
44-
except subprocess.CalledProcessError:
45-
raise PluginDisableException("Unable to get parent process for {0} pid.".format(child_pid))
46-
47-
parent_pid = int(parent_pid.split("\n")[0])
48-
try:
49-
child_pids = subprocess.check_output(['ps', '-opid', '--no-headers', '--ppid', str(parent_pid)],
50-
stderr=subprocess.PIPE, encoding='utf8')
51-
except subprocess.CalledProcessError:
52-
raise PluginDisableException("Unable to get children processes for {0} pid.".format(child_pid))
53-
# we want to return number of ALL PostgreSQL processes meaning parent pid + count(children pids)
54-
# len of the splitted result has extra blank line in the end so we return just the length of
55-
# splitted child pids output
56-
count_child_pids = len(child_pids.split("\n"))
57-
return count_child_pids
58-
5937
def disable_and_exit_if_extension_is_not_installed(self, ext, db=None):
6038
if not self.extension_installed(ext, db=db, silent=True):
6139
self.disable()

0 commit comments

Comments
 (0)