1 # -*- coding: utf-8 -*-
2 # Description: cpufreq netdata python.d plugin
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]
44 self._orig_name = self.chart_name
46 for dirpath, _, filenames in os.walk(self.sys_dir):
47 if self.filename in filenames:
48 self.paths.append(dirpath + "/" + self.filename)
50 if len(self.paths) == 0:
55 for path in self.paths:
56 self.assignment[path] = "cpu" + str(i)
59 for name in self.assignment:
60 dim = self.assignment[name]
61 self.definitions[ORDER[0]]['lines'].append([dim, dim, 'absolute', 1, 1000])
66 self.chart_name = "cpu"
67 status = SimpleService.create(self)
68 self.chart_name = self._orig_name
71 def update(self, interval):
72 self.chart_name = "cpu"
73 status = SimpleService.update(self, interval=interval)
74 self.chart_name = self._orig_name