"example" module fixes
lgz committed
Oct 13, 2017 at 18:37 UTC
7f9afedeee5e29c9b02c5f14b5d0d78df7a847b2
3 files changed
+34
-22
python.d/cpufreq.chart.py
+2
-2
@@ -4,8 +4,8 @@
4
5
import glob
6
import os
7
-import time
8
-from base import SimpleService
7
+
8
+from bases.FrameworkServices.SimpleService import SimpleService
9
10
# default module values (can be overridden per job in `config`)
11
# update_every = 2
python.d/cpuidle.chart.py
+2
-2
@@ -5,8 +5,8 @@
5
import glob
6
import os
7
import platform
8
-import time
9
-from base import SimpleService
8
+
9
+from bases.FrameworkServices.SimpleService import SimpleService
10
11
import ctypes
12
syscall = ctypes.CDLL('libc.so.6').syscall
python.d/example.chart.py
+30
-18
@@ -4,33 +4,45 @@
4
5
import os
6
import random
7
-from base import SimpleService
7
9
-NAME = os.path.basename(__file__).replace(".chart.py", "")
8
+from collections import defaultdict
9
+
10
+from bases.FrameworkServices.SimpleService import SimpleService
11
12
# default module values
13
# update_every = 4
14
priority = 90000
15
retries = 60
16
17
+ORDER = ['random']
18
+CHARTS = {
19
+ 'random': {
20
+ 'options': [None, 'A random number', 'random number', 'random', 'random', 'line'],
21
+ 'lines': [
22
+ ['random1']
23
+ ]
24
+ }
25
+}
26
+
27
28
class Service(SimpleService):
29
def __init__(self, configuration=None, name=None):
19
- super(self.__class__,self).__init__(configuration=configuration, name=name)
30
+ super(self.__class__, self).__init__(configuration=configuration, name=name)
31
+ self.order = ORDER
32
+ self.definitions = CHARTS
33
+ self.data = dict()
34
21
- def check(self):
22
- return True
23
-
24
- def create(self):
25
- self.chart("example.python_random", '', 'A random number', 'random number',
26
- 'random', 'random', 'line', self.priority, self.update_every)
27
- self.dimension('random1')
28
- self.commit()
29
- return True
30
-
31
- def update(self, interval):
32
- self.begin("example.python_random", interval)
33
- self.set("random1", random.randint(0, 100))
34
- self.end()
35
- self.commit()
35
+ @staticmethod
36
+ def check():
37
return True
38
+
39
+ def get_data(self):
40
+ dimension = ''.join(['random', str(random.randint(1, 3))])
41
+
42
+ if dimension not in self.charts['random']:
43
+ self.charts['random'].add_dimension_and_push_chart([dimension])
44
+
45
+ self.data[dimension] = random.randint(0, 100)
46
+
47
+ return self.data
48
+