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 prefix = os.getenv('NETDATA_HOST_PREFIX', "")
25 if prefix.endswith('/'):
27 self.sys_dir = prefix + "/sys/devices"
28 self.filename = "scaling_cur_freq"
29 SimpleService.__init__(self, configuration=configuration, name=name)
31 self.definitions = CHARTS
38 for path in self.paths:
39 with open(path, 'r') as f:
42 for path in self.paths:
43 data[self.assignment[path]] = raw[path]
48 self.sys_dir = str(self.configuration['sys_dir'])
49 except (KeyError, TypeError):
50 self.error("No path specified. Using: '" + self.sys_dir + "'")
52 self._orig_name = self.chart_name
54 for dirpath, _, filenames in os.walk(self.sys_dir):
55 if self.filename in filenames:
56 self.paths.append(dirpath + "/" + self.filename)
58 if len(self.paths) == 0:
59 self.error("cannot find", self.filename)
64 for path in self.paths:
65 self.assignment[path] = "cpu" + str(i)
68 for name in self.assignment:
69 dim = self.assignment[name]
70 self.definitions[ORDER[0]]['lines'].append([dim, dim, 'absolute', 1, 1000])
75 self.chart_name = "cpu"
76 status = SimpleService.create(self)
77 self.chart_name = self._orig_name
80 def update(self, interval):
81 self.chart_name = "cpu"
82 status = SimpleService.update(self, interval=interval)
83 self.chart_name = self._orig_name