3
3
4
4
5
5
class DiskSizes (Plugin ):
6
- AgentPluginType = ' sys'
6
+ AgentPluginType = " sys"
7
7
8
8
query_agent_discovery = "/disk_sizes.sh -j MOUNTPOINT"
9
9
query_agent_used = "df $1 | awk 'NR == 2 {print $$3 * 1024}'"
10
10
query_agent_free = "df $1 | awk 'NR == 2 {print $$4 * 1024}'"
11
11
query_agent_percent_free = "df $1 | awk 'NR == 2 {print 100 - $$5}'"
12
12
# tmp_query_agent_percent_inode_free = " "FIXME for inode
13
- key = ' system.vfs'
13
+ key = " system.vfs"
14
14
15
15
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 )}
18
18
19
19
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
+ ]
30
25
31
26
def run (self , zbx ):
32
- with open ('/proc/self/mountinfo' , 'r' ) as f :
27
+
28
+ with open ("/proc/self/mountinfo" , "r" ) as f :
33
29
34
30
points = []
35
31
@@ -42,109 +38,125 @@ def run(self, zbx):
42
38
vfs = os .statvfs (point )
43
39
except Exception as e :
44
40
self .log .error (
45
- ' Get statvfs for \ ' {0}\ ' error: {1}' .format (point , e ))
41
+ " Get statvfs for '{0}' error: {1}" .format (point , e ))
46
42
continue
47
43
if vfs .f_blocks == 0 or vfs .f_files == 0 :
48
44
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 }))
64
56
65
57
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[]"
68
61
else :
69
- key_discovery = ' system.vfs.discovery'
62
+ key_discovery = " system.vfs.discovery"
70
63
rule = {
71
- ' name' : ' VFS discovery' ,
72
- ' key' : key_discovery
64
+ " name" : " VFS Discovery" ,
65
+ " key" : key_discovery
73
66
}
74
67
if Plugin .old_zabbix :
75
- rule [' filter' ] = ' {#MOUNTPOINT}:.*'
68
+ rule [" filter" ] = " {#MOUNTPOINT}:.*"
76
69
conditions = []
77
70
else :
78
71
conditions = [
79
72
{
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
+ }
85
80
]
86
81
}
87
82
88
83
]
84
+
89
85
items = [
90
86
{
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
+ },
96
93
{
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
+ },
102
100
{
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" :
108
109
items .append (
109
110
{
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
+ },
132
143
]
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 )
144
156
145
157
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 )]
150
162
return template_zabbix .key_and_query (result )
0 commit comments