1 # -*- coding: utf-8 -*-
2 # Description: cpufreq netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
6 from base import SimpleService
8 # default module values (can be overridden per job in `config`)
15 'options': [None, 'CPU Clock', 'MHz', 'cpufreq', None, 'line'],
17 # lines are created dynamically in `check()` method
22 class Service(SimpleService):
23 def __init__(self, configuration=None, name=None):
24 self.sys_dir = "/sys/devices"
25 self.filename = "scaling_cur_freq"
26 SimpleService.__init__(self, configuration=configuration, name=name)
28 self.definitions = CHARTS
35 for path in self.paths:
36 with open(path, 'r') as f:
39 for path in self.paths:
40 data[self.assignment[path]] = raw[path]
45 self.sys_dir = str(self.configuration['sys_dir'])
46 except (KeyError, TypeError):
47 self.error("No path specified. Using: '" + self.sys_dir + "'")
49 self._orig_name = self.chart_name
51 for dirpath, _, filenames in os.walk(self.sys_dir):
52 if self.filename in filenames:
53 self.paths.append(dirpath + "/" + self.filename)
55 if len(self.paths) == 0:
60 for path in self.paths:
61 self.assignment[path] = "cpu" + str(i)
64 for name in self.assignment:
65 dim = self.assignment[name]
66 self.definitions[ORDER[0]]['lines'].append([dim, dim, 'absolute', 1, 1000])
71 self.chart_name = "cpu"
72 status = SimpleService.create(self)
73 self.chart_name = self._orig_name
76 def update(self, interval):
77 self.chart_name = "cpu"
78 status = SimpleService.update(self, interval=interval)
79 self.chart_name = self._orig_name