nginx.chart.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # -*- coding: utf-8 -*-
  2. # Description: nginx netdata python.d module
  3. # Author: Pawel Krupa (paulfantom)
  4. from bases.FrameworkServices.UrlService import UrlService
  5. # default module values (can be overridden per job in `config`)
  6. # update_every = 2
  7. priority = 60000
  8. retries = 60
  9. # default job configuration (overridden by python.d.plugin)
  10. # config = {'local': {
  11. # 'update_every': update_every,
  12. # 'retries': retries,
  13. # 'priority': priority,
  14. # 'url': 'http://localhost/stub_status'
  15. # }}
  16. # charts order (can be overridden if you want less charts, or different order)
  17. ORDER = ['connections', 'requests', 'connection_status', 'connect_rate']
  18. CHARTS = {
  19. 'connections': {
  20. 'options': [None, 'nginx Active Connections', 'connections', 'active connections',
  21. 'nginx.connections', 'line'],
  22. 'lines': [
  23. ["active"]
  24. ]},
  25. 'requests': {
  26. 'options': [None, 'nginx Requests', 'requests/s', 'requests', 'nginx.requests', 'line'],
  27. 'lines': [
  28. ["requests", None, 'incremental']
  29. ]},
  30. 'connection_status': {
  31. 'options': [None, 'nginx Active Connections by Status', 'connections', 'status',
  32. 'nginx.connection_status', 'line'],
  33. 'lines': [
  34. ["reading"],
  35. ["writing"],
  36. ["waiting", "idle"]
  37. ]},
  38. 'connect_rate': {
  39. 'options': [None, 'nginx Connections Rate', 'connections/s', 'connections rate',
  40. 'nginx.connect_rate', 'line'],
  41. 'lines': [
  42. ["accepts", "accepted", "incremental"],
  43. ["handled", None, "incremental"]
  44. ]}
  45. }
  46. class Service(UrlService):
  47. def __init__(self, configuration=None, name=None):
  48. UrlService.__init__(self, configuration=configuration, name=name)
  49. self.url = self.configuration.get('url', 'http://localhost/stub_status')
  50. self.order = ORDER
  51. self.definitions = CHARTS
  52. def _get_data(self):
  53. """
  54. Format data received from http request
  55. :return: dict
  56. """
  57. try:
  58. raw = self._get_raw_data().split(" ")
  59. return {'active': int(raw[2]),
  60. 'requests': int(raw[9]),
  61. 'reading': int(raw[11]),
  62. 'writing': int(raw[13]),
  63. 'waiting': int(raw[15]),
  64. 'accepts': int(raw[7]),
  65. 'handled': int(raw[8])}
  66. except (ValueError, AttributeError):
  67. return None