--- /dev/null
+# -*- coding: utf-8 -*-
+# Description: cpufreq netdata python.d plugin
+# Author: Pawel Krupa (paulfantom)
+
+from base import SysFileService
+
+# default module values (can be overridden per job in `config`)
+# update_every = 2
+
+ORDER = ['cpufreq']
+
+CHARTS = {
+ 'cpufreq': {
+ 'options': [None, 'CPU Clock', 'MHz', 'cpufreq', None, 'line'],
+ 'lines': [
+ # lines are created dynamically in `check()` method
+ ]}
+}
+
+
+class Service(SysFileService):
+ def __init__(self, configuration=None, name=None):
+ SysFileService.__init__(self, configuration=configuration, name=name)
+ self.order = ORDER
+ self.definitions = CHARTS
+ self._orig_name = ""
+
+ def check(self):
+ self._orig_name = self.chart_name
+ self.paths = self._find("scaling_cur_freq")
+
+ if len(self.paths) == 0:
+ return False
+
+ self.paths.sort()
+ i = 0
+ for path in self.paths:
+ self.assignment[path] = "cpu" + str(i)
+ i += 1
+
+ for name in self.assignment:
+ dim = self.assignment[name]
+ self.definitions[ORDER[0]]['lines'].append([dim, dim, 'absolute', 1, 1000])
+
+ return True
+
+ def create(self):
+ self.chart_name = "cpu"
+ status = SysFileService.create(self)
+ self.chart_name = self._orig_name
+ return status
+
+ def update(self, interval):
+ self.chart_name = "cpu"
+ status = SysFileService.update(self, interval=interval)
+ self.chart_name = self._orig_name
+ return status
if self._get_data() is None or len(self._get_data()) == 0:
return False
return True
+
+
+class SysFileService(SimpleService):
+ def __init__(self, configuration=None, name=None):
+ self.paths = []
+ self.sys_dir = "/sys/devices"
+ SimpleService.__init__(self, configuration=configuration, name=name)
+ self.assignment = {}
+
+ def _find(self, query):
+ """
+ Find path to file in /sys/devices
+ :param query: str
+ :return: list
+ """
+ paths = []
+ for dirpath, _, filenames in os.walk(self.sys_dir):
+ if query in filenames:
+ paths.append(dirpath + "/" + query)
+ return paths
+
+ def _get_data(self):
+ raw = {}
+ for path in self.paths:
+ with open(path, 'r') as f:
+ raw[path] = f.read()
+ data = {}
+ for path in self.paths:
+ data[self.assignment[path]] = raw[path]
+ return data