1 # -*- coding: utf-8 -*-
2 # Description: cpufreq netdata python.d module
3 # Author: Pawel Krupa (paulfantom) and Steven Noonan (tycho)
7 from base import SimpleService
9 # default module values (can be overridden per job in `config`)
16 'options': [None, 'CPU Clock', 'MHz', 'cpufreq', None, 'line'],
18 # 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 SimpleService.__init__(self, configuration=configuration, name=name)
30 self.definitions = CHARTS
38 for name, path in self.assignment.items():
40 for line in open(path, 'r'):
41 line = list(map(int, line.split()))
42 total += (line[0] * line[1]) / 100
45 for name, path in self.assignment.items():
46 data[name] = open(path, 'r').read()
51 self.sys_dir = str(self.configuration['sys_dir'])
52 except (KeyError, TypeError):
53 self.error("No path specified. Using: '" + self.sys_dir + "'")
55 self._orig_name = self.chart_name
57 for path in glob.glob(self.sys_dir + '/system/cpu/cpu*/cpufreq/stats/time_in_state'):
58 if len(open(path, 'rb').read().rstrip()) == 0:
59 self.alert("time_in_state is empty, broken cpufreq_stats data")
62 path_elem = path.split('/')
64 self.assignment[cpu] = path
66 if len(self.assignment) == 0:
67 self.alert("trying less accurate scaling_cur_freq method")
70 for path in glob.glob(self.sys_dir + '/system/cpu/cpu*/cpufreq/scaling_cur_freq'):
71 path_elem = path.split('/')
73 self.assignment[cpu] = path
75 if len(self.assignment) == 0:
76 self.error("couldn't find a method to read cpufreq statistics")
84 for name in self.assignment.keys():
85 self.definitions[ORDER[0]]['lines'].append([name, name, algo, 1, 1000])
90 self.chart_name = "cpu"
91 status = SimpleService.create(self)
92 self.chart_name = self._orig_name
95 def update(self, interval):
96 self.chart_name = "cpu"
97 status = SimpleService.update(self, interval=interval)
98 self.chart_name = self._orig_name