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