Skip to content

Commit dc75e58

Browse files
committed
Add a code to get all I/Os data from valid Zabbix FS mount point
1 parent 7acb12a commit dc75e58

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

scripts/diskstats.py

100755100644
Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env python
22
''' Copyright (c) 2015 Jean Baptiste Favre.
33
Script for monitoring disks stats from Zabbix.
4+
Only add valid mounted point to monitoring
45
'''
56

7+
import os
8+
import re
69
import sys
710
import socket
811
import protobix
@@ -11,6 +14,7 @@ class DiskStats(protobix.SampleProbe):
1114

1215
__version__ = '0.0.9'
1316
discovery_key = 'diskstats.discovery'
17+
authorized_fs_type = '^(btrfs|ext2|ext3|ext4|jfs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|ntfs|fat32)$'
1418

1519
def _parse_args(self):
1620
parser = super( DiskStats, self)._parse_args()
@@ -51,26 +55,40 @@ def _diskstats_parse(self, dev=None):
5155
def _init_probe(self):
5256
self.hostname = socket.getfqdn()
5357

54-
def _get_discovery(self):
55-
data = {self.discovery_key:[]}
56-
for disk in ['sda', 'sdb', 'sdc', 'sdd']:
57-
element = { '{#DISKNAME}': disk }
58-
data[self.discovery_key].append(element)
59-
return { self.hostname: data }
58+
def _get_mount_points(self):
59+
data = []
60+
mounted_file = '/proc/mounts'
61+
p = re.compile(self.authorized_fs_type)
62+
lines = open(mounted_file, 'r').readlines()
63+
for line in lines:
64+
if line == '': continue
65+
split = line.split()
66+
device_full_name = split[0]
67+
mount_point = split[1]
68+
fs_type = split[2]
69+
if device_full_name[0] == '/' and p.match(fs_type):
70+
# Mounted disk device
71+
real_device_name = device_full_name
72+
if os.path.islink(real_device_name):
73+
real_device_name = os.path.realpath(device_full_name)
74+
short_real_device_name = os.path.basename(real_device_name)
75+
element = [ short_real_device_name, device_full_name , mount_point , fs_type]
76+
data.append(element)
77+
return data
6078

6179
def _get_metrics(self):
6280
data = {}
63-
for disk in ['sda', 'sdb', 'sdc', 'sdd']:
64-
diskstat = self._diskstats_parse(disk)
81+
for disk in self._get_mount_points():
82+
diskstat = self._diskstats_parse(disk[0])
6583
if diskstat != {}:
66-
for key in diskstat[disk]:
84+
for key in diskstat[disk[0]]:
6785
zbx_key = "diskstats[{0},{1}]"
68-
zbx_key = zbx_key.format(disk, key)
69-
data[zbx_key] = diskstat[disk][key]
86+
zbx_key = zbx_key.format(disk[2], key)
87+
data[zbx_key] = diskstat[disk[0]][key]
7088
data["diskstats.zbx_version"] = self.__version__
7189
return { self.hostname: data }
7290

7391
if __name__ == '__main__':
7492
ret = DiskStats().run()
7593
print((ret))
76-
sys.exit(ret)
94+
sys.exit(ret)

0 commit comments

Comments
 (0)