1 # -*- coding: utf-8 -*-
2 # Description: mdstat netdata python.d module
5 from base import SimpleService
12 class Service(SimpleService):
13 def __init__(self, configuration=None, name=None):
14 SimpleService.__init__(self, configuration=configuration, name=name)
15 self.order = ['agr_health']
16 self.definitions = {'agr_health':
18 [None, 'Faulty devices in MD', 'failed disks', 'health', 'md.health', 'line'],
20 self.proc_mdstat = '/proc/mdstat'
21 self.regex_disks = compile(r'((?<=\ )[a-zA-Z_0-9]+(?= : active)).*?((?<= \[)[0-9]+)/([0-9]+(?=\] ))')
24 raw_data = self._get_raw_data()
26 self.error('Cant read mdstat data from %s' % (self.proc_mdstat))
29 md_list = [md[0] for md in self.regex_disks.findall(raw_data)]
32 self.definitions['agr_health']['lines'].append([''.join([md, '_health']), md, 'absolute'])
33 self.definitions[md] = {'options':
34 [None, 'MD disks stats', 'disks', md, 'md.stats', 'stacked'],
35 'lines': [[''.join([md, '_total']), 'total', 'absolute'],
36 [''.join([md, '_inuse']), 'inuse', 'absolute']]}
37 self.info('Plugin was started successfully. MDs to monitor %s' % (md_list))
41 def _get_raw_data(self):
43 Read data from /proc/mdstat
47 with open(self.proc_mdstat, 'rt') as proc_mdstat:
48 raw_result = proc_mdstat.read()
52 raw_result = ' '.join(raw_result.split())
57 Parse data from _get_raw_data()
60 raw_mdstat = self._get_raw_data()
61 mdstat = self.regex_disks.findall(raw_mdstat)
65 to_netdata[''.join([md[0], '_total'])] = int(md[1])
66 to_netdata[''.join([md[0], '_inuse'])] = int(md[2])
67 to_netdata[''.join([md[0], '_health'])] = int(md[1]) - int(md[2])