remove SysFileService prototype
paulfantom committed
Jul 7, 2016 at 00:54 UTC
8d31f4703d1d491b036a1f9e0646d74e16992510
2 files changed
+24
-36
python.d/cpufreq.chart.py
+24
-6
@@ -2,7 +2,8 @@
2
# Description: cpufreq netdata python.d plugin
3
# Author: Pawel Krupa (paulfantom)
4
5
-from base import SysFileService
5
+import os
6
+from base import SimpleService
7
8
# default module values (can be overridden per job in `config`)
9
# update_every = 2
@@ -18,16 +19,33 @@ CHARTS = {
19
}
20
21
21
-class Service(SysFileService):
22
+class Service(SimpleService):
23
def __init__(self, configuration=None, name=None):
23
- SysFileService.__init__(self, configuration=configuration, name=name)
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
30
- self.paths = self._find("scaling_cur_freq")
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
@@ -46,12 +64,12 @@ class Service(SysFileService):
64
65
def create(self):
66
self.chart_name = "cpu"
49
- status = SysFileService.create(self)
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"
55
- status = SysFileService.update(self, interval=interval)
73
+ status = SimpleService.update(self, interval=interval)
74
self.chart_name = self._orig_name
75
return status
python.d/python_modules/base.py
-30
@@ -609,33 +609,3 @@ class ExecutableService(SimpleService):
609
if self._get_data() is None or len(self._get_data()) == 0:
610
return False
611
return True
612
-
613
-
614
-class SysFileService(SimpleService):
615
- def __init__(self, configuration=None, name=None):
616
- self.paths = []
617
- self.sys_dir = "/sys/devices"
618
- SimpleService.__init__(self, configuration=configuration, name=name)
619
- self.assignment = {}
620
-
621
- def _find(self, query):
622
- """
623
- Find path to file in /sys/devices
624
- :param query: str
625
- :return: list
626
- """
627
- paths = []
628
- for dirpath, _, filenames in os.walk(self.sys_dir):
629
- if query in filenames:
630
- paths.append(dirpath + "/" + query)
631
- return paths
632
-
633
- def _get_data(self):
634
- raw = {}
635
- for path in self.paths:
636
- with open(path, 'r') as f:
637
- raw[path] = f.read()
638
- data = {}
639
- for path in self.paths:
640
- data[self.assignment[path]] = raw[path]
641
- return data