8000 refactoring: refactored Common plugins · postgrespro/mamonsu@de41330 · GitHub
[go: up one dir, main page]

Skip to content

Commit de41330

Browse files
committed
refactoring: refactored Common plugins
1 parent 36db427 commit de41330

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

mamonsu/plugins/common/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
__all__ = ['health']
1+
__all__ = ["health"]
2+
23
from . import *

mamonsu/plugins/common/health.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,46 @@
66

77

88
class Health(Plugin):
9-
AgentPluginType = 'sys'
109

11-
DEFAULT_CONFIG = {'max_memory_usage': str(40 * 1024 * 1024)}
10+
AgentPluginType = "sys"
11+
12+
DEFAULT_CONFIG = {
13+
"max_memory_usage": str(40 * 1024 * 1024)
14+
}
1215

1316
counter = 0
1417

1518
def run(self, zbx):
16-
zbx.send('mamonsu.plugin.keepalive[]', 0)
19+
zbx.send("mamonsu.plugin.keepalive[]", 0)
1720
if platform.LINUX:
1821
usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * 1024
19-
zbx.send('mamonsu.memory.rss[max]', usage)
22+
zbx.send("mamonsu.memory.rss[max]", usage)
2023
self.counter += 1
2124
if self.counter > 9:
22-
self.log.info('=== Keep alive ===')
25+
self.log.info("=== Keep alive ===")
2326
self.counter = 0
2427

2528
def items(self, template, dashboard=False):
2629
# see supervisor.py:
2730
if self.Type == "mamonsu":
2831
result = template.item({
29-
'name': 'Mamonsu: plugin errors',
30-
'key': 'mamonsu.plugin.errors[]',
31-
'value_type': Plugin.VALUE_TYPE.text # text
32+
"name": "Mamonsu: Plugin Errors",
33+
"key": "mamonsu.plugin.errors[]",
34+
"value_type": Plugin.VALUE_TYPE.text # text
3235
}) + template.item({
33-
'name': 'Mamonsu: plugin keep alive',
34-
'key': self.right_type("mamonsu.plugin.keepalive{0}")
36+
"name": "Mamonsu: Plugin Keep Alive",
37+
"key": self.right_type("mamonsu.plugin.keepalive{0}")
3538
})
3639
if platform.LINUX:
3740
result += template.item({
38-
'name': 'Mamonsu: rss memory max usage',
39-
'key': 'mamonsu.memory.rss[max]',
40-
'units': Plugin.UNITS.bytes
41+
"name": "Mamonsu: RSS Memory Max Usage",
42+
"key": "mamonsu.memory.rss[max]",
43+
"units": Plugin.UNITS.bytes
4144
})
4245
else:
4346
result = template.item({
44-
'name': 'Mamonsu: plugin keep alive',
45-
'key': self.right_type("mamonsu.plugin.keepalive{0}")
47+
"name": "Mamonsu: Plugin Keep Alive",
48+
"key": self.right_type("mamonsu.plugin.keepalive{0}")
4649
})
4750
if not dashboard:
4851
return result
@@ -52,31 +55,25 @@ def items(self, template, dashboard=False):
5255
def triggers(self, template, dashboard=False):
5356
if self.Type == "mamonsu":
5457
result = template.trigger({
55-
'name': 'Mamonsu plugin errors '
56-
'on {HOSTNAME}. {ITEM.LASTVALUE}',
57-
'expression': '{#TEMPLATE:mamonsu.plugin.errors[].strlen()'
58-
'}>1'
58+
"name": "Mamonsu plugin errors on {HOSTNAME}. {ITEM.LASTVALUE}",
59+
"expression": "{#TEMPLATE:mamonsu.plugin.errors[].strlen()}>1"
5960
}) + template.trigger({
60-
'name': 'Mamonsu nodata from {HOSTNAME}',
61-
'expression': '{#TEMPLATE:' + self.right_type("mamonsu.plugin.keepalive{0}") +
62-
'.nodata(180)}=1'
61+
"name": "Mamonsu nodata from {HOSTNAME}",
62+
"expression": "{#TEMPLATE:" + self.right_type("mamonsu.plugin.keepalive{0}") + ".nodata(180)}=1"
6363
})
6464
if platform.LINUX:
6565
result += template.trigger({
66-
'name': 'Mamonsu agent memory usage alert '
67-
'on {HOSTNAME}: {ITEM.LASTVALUE} bytes',
68-
'expression': '{#TEMPLATE:mamonsu.memory.rss[max].last()}'
69-
'>' + self.plugin_config('max_memory_usage')
66+
"name": "Mamonsu agent memory usage alert on {HOSTNAME}: {ITEM.LASTVALUE} bytes",
67+
"expression": "{#TEMPLATE:mamonsu.memory.rss[max].last()}>" + self.plugin_config(
68+
"max_memory_usage")
7069
})
7170
else:
7271
result = template.trigger({
73-
'name': 'Mamonsu nodata from {HOSTNAME}',
74-
'expression': '{#TEMPLATE:' + self.right_type("mamonsu.plugin.keepalive{0}") +
75-
'.nodata(180)}=1'
72+
"name": "Mamonsu nodata from {HOSTNAME}",
73+
"expression": "{#TEMPLATE:" + self.right_type("mamonsu.plugin.keepalive{0}") + ".nodata(180)}=1"
7674
})
7775
return result
7876

7977
def keys_and_queries(self, template_zabbix):
80-
result = ['{0},{1}'.format("mamonsu.plugin.keepalive", "echo 0")]
78+
result = ["{0},{1}".format("mamonsu.plugin.keepalive", "echo 0")]
8179
return template_zabbix.key_and_query(result)
82-

0 commit comments

Comments
 (0)
0