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

Skip to content

Commit 36db427

Browse files
committed
refactoring: refactored System plugins
1 parent 3cbeb49 commit 36db427

20 files changed

+733
-615
lines changed

mamonsu/plugins/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__import__('mamonsu.plugins.common')
2-
__import__('mamonsu.plugins.pgsql')
3-
__import__('mamonsu.plugins.system')
1+
__import__("mamonsu.plugins.common")
2+
__import__("mamonsu.plugins.pgsql")
3+
__import__("mamonsu.plugins.system")

mamonsu/plugins/system/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import mamonsu.lib.platform as platform
22

3-
43
if platform.LINUX:
5-
__import__('mamonsu.plugins.system.linux')
4+
__import__("mamonsu.plugins.system.linux")
65
if platform.WINDOWS:
7-
__import__('mamonsu.plugins.system.windows')
6+
__import__("mamonsu.plugins.system.windows")
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
__all__ = [
2-
'proc_stat', 'disk_stats', 'disk_sizes',
3-
'memory', 'uptime', 'open_files', 'net', 'la'
4-
,'pg_probackup'
5-
]
1+
__all__ = ["proc_stat", "disk_stats", "disk_sizes", "memory", "uptime", "open_files", "net", "la", "pg_probackup"]
62

73
from . import *

mamonsu/plugins/system/linux/disk_sizes.py

Lines changed: 106 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,29 @@
33

44

55
class DiskSizes(Plugin):
6-
AgentPluginType = 'sys'
6+
AgentPluginType = "sys"
77

88
query_agent_discovery = "/disk_sizes.sh -j MOUNTPOINT"
99
query_agent_used = "df $1 | awk 'NR == 2 {print $$3 * 1024}'"
1010
query_agent_free = "df $1 | awk 'NR == 2 {print $$4 * 1024}'"
1111
query_agent_percent_free = "df $1 | awk 'NR == 2 {print 100 - $$5}'"
1212
# tmp_query_agent_percent_inode_free = " "FIXME for inode
13-
key = 'system.vfs'
13+
key = "system.vfs"
1414

1515
DEFAULT_CONFIG = {
16-
'vfs_percent_free': str(10),
17-
'vfs_inode_percent_free': str(10)}
16+
"vfs_percent_free": str(10),
17+
"vfs_inode_percent_free": str(10)}
1818

1919
ExcludeFsTypes = [
20-
'none', 'unknown', 'rootfs', 'iso9660',
21-
'squashfs', 'udf', 'romfs', 'ramfs',
22-
'debugfs', 'cgroup', 'cgroup_root',
23-
'pstore', 'devtmpfs', 'autofs',
24-
'cgroup', 'configfs', 'devpts',
25-
'efivarfs', 'fusectl', 'fuse.gvfsd-fuse',
26-
'hugetlbfs', 'mqueue', 'binfmt_misc',
27-
'nfsd', 'proc', 'pstore', 'selinuxfs'
28-
'rpc_pipefs', 'securityfs', 'sysfs',
29-
'nsfs', 'tmpfs', 'tracefs']
20+
"none", "unknown", "rootfs", "iso9660", "squashfs", "udf", "romfs", "ramfs", "debugfs", "cgroup", "cgroup_root",
21+
"pstore", "devtmpfs", "autofs", "cgroup", "configfs", "devpts", "efivarfs", "fusectl", "fuse.gvfsd-fuse",
22+
"hugetlbfs", "mqueue", "binfmt_misc", "nfsd", "proc", "pstore", "selinuxfs", "rpc_pipefs", "securityfs",
23+
"sysfs", "nsfs", "tmpfs", "tracefs"
24+
]
3025

3126
def run(self, zbx):
32-
with open('/proc/self/mountinfo', 'r') as f:
27+
28+
with open("/proc/self/mountinfo", "r") as f:
3329

3430
points = []
3531

@@ -42,109 +38,125 @@ def run(self, zbx):
4238
vfs = os.statvfs(point)
4339
except Exception as e:
4440
self.log.error(
45-
'Get statvfs for \'{0}\' error: {1}'.format(point, e))
41+
"Get statvfs for '{0}' error: {1}".format(point, e))
4642
continue
4743
if vfs.f_blocks == 0 or vfs.f_files == 0:
4844
continue
49-
points.append({'{#MOUNTPOINT}': point})
50-
zbx.send(
51-
'system.vfs.used[{0}]'.format(point),
52-
int((vfs.f_blocks - vfs.f_bfree) * vfs.f_bsize))
53-
zbx.send(
54-
'system.vfs.free[{0}]'.format(point),
55-
int(vfs.f_bfree * vfs.f_bsize))
56-
zbx.send(
57-
'system.vfs.percent_free[{0}]'.format(point),
58-
100 - (float(vfs.f_blocks - vfs.f_bfree) * 100 / vfs.f_blocks))
59-
zbx.send(
60- 8000
'system.vfs.percent_inode_free[{0}]'.format(point),
61-
100 - (float(vfs.f_files - vfs.f_ffree) * 100 / vfs.f_files))
62-
63-
zbx.send('system.vfs.discovery[]', zbx.json({'data': points}))
45+
points.append({"{#MOUNTPOINT}": point})
46+
zbx.send("system.vfs.used[{0}]".format(point),
47+
int((vfs.f_blocks - vfs.f_bfree) * vfs.f_bsize))
48+
zbx.send("system.vfs.free[{0}]".format(point),
49+
int(vfs.f_bfree * vfs.f_bsize))
50+
zbx.send("system.vfs.percent_free[{0}]".format(point),
51+
100 - (float(vfs.f_blocks - vfs.f_bfree) * 100 / vfs.f_blocks))
52+
zbx.send("system.vfs.percent_inode_free[{0}]".format(point),
53+
100 - (float(vfs.f_files - vfs.f_ffree) * 100 / vfs.f_files))
54+
55+
zbx.send("system.vfs.discovery[]", zbx.json({"data": points}))
6456

6557
def discovery_rules(self, template, dashboard=False):
66-
if Plugin.Type == 'mamonsu':
67-
key_discovery = 'system.vfs.discovery[]'
58+
59+
if Plugin.Type == "mamonsu":
60+
key_discovery = "system.vfs.discovery[]"
6861
else:
69-
key_discovery = 'system.vfs.discovery'
62+
key_discovery = "system.vfs.discovery"
7063
rule = {
71-
'name': 'VFS discovery',
72-
'key': key_discovery
64+
"name": "VFS Discovery",
65+
"key": key_discovery
7366
}
7467
if Plugin.old_zabbix:
75-
rule['filter'] = '{#MOUNTPOINT}:.*'
68+
rule["filter"] = "{#MOUNTPOINT}:.*"
7669
conditions = []
7770
else:
7871
conditions = [
7972
{
80-
'condition': [
81-
{'macro': '{#MOUNTPOINT}',
82-
'value': '.*',
83-
'operator': 8,
84-
'formulaid': 'A'}
73+
"condition": [
74+
{
75+
"macro": "{#MOUNTPOINT}",
76+
"value": ".*",
77+
"operator": 8,
78+
"formulaid": "A"
79+
}
8580
]
8681
}
8782

8883
]
84+
8985
items = [
9086
{
91-
'key': 'system.vfs.used[{#MOUNTPOINT}]',
92-
'name': 'Mount point {#MOUNTPOINT}: used',
93-
'value_type': Plugin.VALUE_TYPE.numeric_unsigned,
94-
'delay': self.plugin_config('interval'),
95-
'units': Plugin.UNITS.bytes},
87+
"key": "system.vfs.used[{#MOUNTPOINT}]",
88+
"name": "System: Mount Point {#MOUNTPOINT}: Used",
89+
"value_type": Plugin.VALUE_TYPE.numeric_unsigned,
90+
"delay": self.plugin_config("interval"),
91+
"units": Plugin.UNITS.bytes
92+
},
9693
{
97-
'key': 'system.vfs.free[{#MOUNTPOINT}]',
98-
'name': 'Mount point {#MOUNTPOINT}: free',
99-
'value_type': Plugin.VALUE_TYPE.numeric_unsigned,
100-
'delay': self.plugin_config('interval'),
101-
'units': Plugin.UNITS.bytes},
94+
"key": "system.vfs.free[{#MOUNTPOINT}]",
95+
"name": "System: Mount Point {#MOUNTPOINT}: Free",
96+
"value_type": Plugin.VALUE_TYPE.numeric_unsigned,
97+
"delay": self.plugin_config("interval"),
98+
"units": Plugin.UNITS.bytes
99+
},
102100
{
103-
'key': 'system.vfs.percent_free[{#MOUNTPOINT}]',
104-
'name': 'Mount point {#MOUNTPOINT}: free in percents',
105-
'delay': self.plugin_config('interval'),
106-
'units': Plugin.UNITS.percent}]
107-
if Plugin.Type == 'mamonsu':
101+
"key": "system.vfs.percent_free[{#MOUNTPOINT}]",
102+
"name": "System: Mount Point {#MOUNTPOINT}: Free in Percents",
103+
"delay": self.plugin_config("interval"),
104+
"units": Plugin.UNITS.percent
105+
}
106+
]
107+
108+
if Plugin.Type == "mamonsu":
108109
items.append(
109110
{
110-
'key': 'system.vfs.percent_inode_free[{#MOUNTPOINT}]',
111-
'name': 'Mount point {#MOUNTPOINT}: free inodes in percent',
112-
'delay': self.plugin_config('interval'),
113-
'units': Plugin.UNITS.percent})
114-
115-
graphs = [{
116-
'name': 'Mount point overview: {#MOUNTPOINT}',
117-
'type': self.GRAPH_TYPE.stacked,
118-
'items': [{
119-
'color': 'E57862',
120-
'key': 'system.vfs.used[{#MOUNTPOINT}]'},
121-
{
122-
'color': '578159',
123-
'key': 'system.vfs.free[{#MOUNTPOINT}]'}]
124-
}]
125-
126-
triggers = [{
127-
'name': 'Free disk space less then 10% on mountpoint '
128-
'{#MOUNTPOINT} (hostname={HOSTNAME} value={ITEM.LASTVALUE})',
129-
'expression': '{#TEMPLATE:system.vfs.'
130-
'percent_free[{#MOUNTPOINT}].last'
131-
'()}<' + self.plugin_config('vfs_percent_free')},
111+
"key": "system.vfs.percent_inode_free[{#MOUNTPOINT}]",
112+
"name": "System: Mount Point {#MOUNTPOINT} Free Inodes in Percent",
113+
"delay": self.plugin_config("interval"),
114+
"units": Plugin.UNITS.percent
115+
}
116+
)
117+
118+
graphs = [
119+
{
120+
"name": "System: Mount Point Overview {#MOUNTPOINT}",
121+
"type": self.GRAPH_TYPE.stacked,
122+
"items": [
123+
{
124+
"color": "E57862",
125+
"key": "system.vfs.used[{#MOUNTPOINT}]"
126+
},
127+
{
128+
"color": "578159",
129+
"key": "system.vfs.free[{#MOUNTPOINT}]"
130+
}
131+
]
132+
}
133+
]
134+
135+
triggers = [
136+
{
137+
"name": "Free disk space less then 10% on mountpoint "
138+
"{#MOUNTPOINT} (hostname={HOSTNAME} value={ITEM.LASTVALUE})",
139+
"expression": "{#TEMPLATE:system.vfs."
140+
"percent_free[{#MOUNTPOINT}].last"
141+
"()}<" + self.plugin_config("vfs_percent_free")
142+
},
132143
]
133-
if Plugin.Type == 'mamonsu':
134-
triggers.append({
135-
'name': 'Free inode space less then 10% on mountpoint '
136-
'{#MOUNTPOINT} (hostname={HOSTNAME} value={ITEM.LASTVALUE})',
137-
'expression': '{#TEMPLATE:system.vfs.'
138-
'percent_inode_free[{#MOUNTPOINT}].last'
139-
'()}<' + self.plugin_config('vfs_inode_percent_free')
140-
})
141-
142-
return template.discovery_rule(
143-
rule=rule, conditions=conditions, items=items, graphs=graphs, triggers=triggers)
144+
145+
if Plugin.Type == "mamonsu":
146+
triggers.append(
147+
{
148+
"name": "Free inode space less then 10% on mountpoint "
149+
"{#MOUNTPOINT} (hostname={HOSTNAME} value={ITEM.LASTVALUE})",
150+
"expression": "{#TEMPLATE:system.vfs.percent_inode_free[{#MOUNTPOINT}].last"
151+
"()}<" + self.plugin_config("vfs_inode_percent_free")
152+
}
153+
)
154+
155+
return template.discovery_rule(rule=rule, conditions=conditions, items=items, graphs=graphs, triggers=triggers)
144156

145157
def keys_and_queries(self, template_zabbix):
146-
result = ['system.vfs.discovery,{0}{1}'.format(Plugin.PATH, self.query_agent_discovery),
147-
'system.vfs.used[*],{0}'.format(self.query_agent_used),
148-
'system.vfs.free[*],{0}'.format(self.query_agent_free),
149-
'system.vfs.percent_free[*],{0}'.format(self.query_agent_percent_free)]
158+
result = ["system.vfs.discovery,{0}{1}".format(Plugin.PATH, self.query_agent_discovery),
159+
"system.vfs.used[*],{0}".format(self.query_agent_used),
160+
"system.vfs.free[*],{0}".format(self.query_agent_free),
161+
"system.vfs.percent_free[*],{0}".format(self.query_agent_percent_free)]
150162
return template_zabbix.key_and_query(result)

0 commit comments

Comments
 (0)
0