example.chart.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # Description: example netdata python.d module
  3. # Author: Put your name here (your github login)
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. from random import SystemRandom
  6. from bases.FrameworkServices.SimpleService import SimpleService
  7. priority = 90000
  8. ORDER = [
  9. 'random',
  10. ]
  11. CHARTS = {
  12. 'random': {
  13. 'options': [None, 'A random number', 'random number', 'random', 'random', 'line'],
  14. 'lines': [
  15. ['random1']
  16. ]
  17. }
  18. }
  19. class Service(SimpleService):
  20. def __init__(self, configuration=None, name=None):
  21. SimpleService.__init__(self, configuration=configuration, name=name)
  22. self.order = ORDER
  23. self.definitions = CHARTS
  24. self.random = SystemRandom()
  25. self.num_lines = self.configuration.get('num_lines', 4)
  26. self.lower = self.configuration.get('lower', 0)
  27. self.upper = self.configuration.get('upper', 100)
  28. @staticmethod
  29. def check():
  30. return True
  31. def get_data(self):
  32. data = dict()
  33. for i in range(0, self.num_lines):
  34. dimension_id = ''.join(['random', str(i)])
  35. if dimension_id not in self.charts['random']:
  36. self.charts['random'].add_dimension([dimension_id])
  37. data[dimension_id] = self.random.randint(self.lower, self.upper)
  38. return data