]> arthur.barton.de Git - netdata.git/blob - python.d/nginx.chart.py
dns_query_time plugin: added
[netdata.git] / python.d / nginx.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: nginx netdata python.d module
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 = 60
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': [None, 'nginx Active Connections', 'connections', 'active connections', 'nginx.connections', 'line'],
26         'lines': [
27             ["active"]
28         ]},
29     'requests': {
30         'options': [None, 'nginx Requests', 'requests/s', 'requests', 'nginx.requests', 'line'],
31         'lines': [
32             ["requests", None, 'incremental']
33         ]},
34     'connection_status': {
35         'options': [None, 'nginx Active Connections by Status', 'connections', 'status', 'nginx.connection_status', 'line'],
36         'lines': [
37             ["reading"],
38             ["writing"],
39             ["waiting", "idle"]
40         ]},
41     'connect_rate': {
42         'options': [None, 'nginx Connections Rate', 'connections/s', 'connections rate', 'nginx.connect_rate', 'line'],
43         'lines': [
44             ["accepts", "accepted", "incremental"],
45             ["handled", None, "incremental"]
46         ]}
47 }
48
49
50 class Service(UrlService):
51     def __init__(self, configuration=None, name=None):
52         UrlService.__init__(self, configuration=configuration, name=name)
53         if len(self.url) == 0:
54             self.url = "http://localhost/stub_status"
55         self.order = ORDER
56         self.definitions = CHARTS
57
58     def _get_data(self):
59         """
60         Format data received from http request
61         :return: dict
62         """
63         try:
64             raw = self._get_raw_data().split(" ")
65             return {'active': int(raw[2]),
66                     'requests': int(raw[9]),
67                     'reading': int(raw[11]),
68                     'writing': int(raw[13]),
69                     'waiting': int(raw[15]),
70                     'accepts': int(raw[7]),
71                     'handled': int(raw[8])}
72         except (ValueError, AttributeError):
73             return None