Browse Source

example module update

lgz 7 years ago
parent
commit
8e7a2ceb65
1 changed files with 10 additions and 8 deletions
  1. 10 8
      python.d/example.chart.py

+ 10 - 8
python.d/example.chart.py

@@ -2,7 +2,7 @@
 # Description: example netdata python.d module
 # Author: Pawel Krupa (paulfantom)
 
-import random
+from random import SystemRandom
 
 from bases.FrameworkServices.SimpleService import SimpleService
 
@@ -24,22 +24,24 @@ CHARTS = {
 
 class Service(SimpleService):
     def __init__(self, configuration=None, name=None):
-        super(self.__class__, self).__init__(configuration=configuration, name=name)
+        SimpleService.__init__(self, configuration=configuration, name=name)
         self.order = ORDER
         self.definitions = CHARTS
-        self.data = dict()
+        self.random = SystemRandom()
 
     @staticmethod
     def check():
         return True
 
     def get_data(self):
-        dimension = ''.join(['random', str(random.randint(1, 3))])
+        data = dict()
 
-        if dimension not in self.charts['random']:
-            self.charts['random'].add_dimension([dimension])
+        for i in range(1, 4):
+            dimension_id = ''.join(['random', str(i)])
 
-        self.data[dimension] = random.randint(0, 100)
+            if dimension_id not in self.charts['random']:
+                self.charts['random'].add_dimension([dimension_id])
 
-        return self.data
+            data[dimension_id] = self.random.randint(0, 100)
 
+        return data