]> arthur.barton.de Git - netdata.git/blob - python.d/cpufreq.chart.py
cpufreq + 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 from base import SysFileService
6
7 # default module values (can be overridden per job in `config`)
8 # update_every = 2
9
10 ORDER = ['cpufreq']
11
12 CHARTS = {
13     'cpufreq': {
14         'options': [None, 'CPU Clock', 'MHz', 'cpufreq', None, 'line'],
15         'lines': [
16             # lines are created dynamically in `check()` method
17         ]}
18 }
19
20
21 class Service(SysFileService):
22     def __init__(self, configuration=None, name=None):
23         SysFileService.__init__(self, configuration=configuration, name=name)
24         self.order = ORDER
25         self.definitions = CHARTS
26         self._orig_name = ""
27
28     def check(self):
29         self._orig_name = self.chart_name
30         self.paths = self._find("scaling_cur_freq")
31
32         if len(self.paths) == 0:
33             return False
34
35         self.paths.sort()
36         i = 0
37         for path in self.paths:
38             self.assignment[path] = "cpu" + str(i)
39             i += 1
40
41         for name in self.assignment:
42             dim = self.assignment[name]
43             self.definitions[ORDER[0]]['lines'].append([dim, dim, 'absolute', 1, 1000])
44
45         return True
46
47     def create(self):
48         self.chart_name = "cpu"
49         status = SysFileService.create(self)
50         self.chart_name = self._orig_name
51         return status
52
53     def update(self, interval):
54         self.chart_name = "cpu"
55         status = SysFileService.update(self, interval=interval)
56         self.chart_name = self._orig_name
57         return status