]> arthur.barton.de Git - netdata.git/blob - python.d/cpufreq.chart.py
remove SysFileService prototype
[netdata.git] / python.d / cpufreq.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: cpufreq netdata python.d plugin
3 # Author: Pawel Krupa (paulfantom)
4
5 import os
6 from base import SimpleService
7
8 # default module values (can be overridden per job in `config`)
9 # update_every = 2
10
11 ORDER = ['cpufreq']
12
13 CHARTS = {
14     'cpufreq': {
15         'options': [None, 'CPU Clock', 'MHz', 'cpufreq', None, 'line'],
16         'lines': [
17             # lines are created dynamically in `check()` method
18         ]}
19 }
20
21
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)
27         self.order = ORDER
28         self.definitions = CHARTS
29         self._orig_name = ""
30         self.assignment = {}
31         self.paths = []
32
33     def _get_data(self):
34         raw = {}
35         for path in self.paths:
36             with open(path, 'r') as f:
37                 raw[path] = f.read()
38         data = {}
39         for path in self.paths:
40             data[self.assignment[path]] = raw[path]
41         return data
42
43     def check(self):
44         self._orig_name = self.chart_name
45
46         for dirpath, _, filenames in os.walk(self.sys_dir):
47             if self.filename in filenames:
48                 self.paths.append(dirpath + "/" + self.filename)
49
50         if len(self.paths) == 0:
51             return False
52
53         self.paths.sort()
54         i = 0
55         for path in self.paths:
56             self.assignment[path] = "cpu" + str(i)
57             i += 1
58
59         for name in self.assignment:
60             dim = self.assignment[name]
61             self.definitions[ORDER[0]]['lines'].append([dim, dim, 'absolute', 1, 1000])
62
63         return True
64
65     def create(self):
66         self.chart_name = "cpu"
67         status = SimpleService.create(self)
68         self.chart_name = self._orig_name
69         return status
70
71     def update(self, interval):
72         self.chart_name = "cpu"
73         status = SimpleService.update(self, interval=interval)
74         self.chart_name = self._orig_name
75         return status