]> arthur.barton.de Git - netdata.git/blob - python.d/apache.chart.py
41d7808a7159760711b3efbc6afae9c3be918838
[netdata.git] / python.d / apache.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: apache 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://www.apache.org/server-status?auto'
18 #          }}
19
20 # charts order (can be overridden if you want less charts, or different order)
21 ORDER = ['bytesperreq', 'workers', 'reqpersec', 'bytespersec', 'requests', 'net', 'connections', 'conns_async']
22
23 CHARTS = {
24     'bytesperreq': {
25         'options': "'' 'apache Lifetime Avg. Response Size' 'bytes/request' statistics apache.bytesperreq area",
26         'lines': [
27             {"name": "size_req",
28              "options": "'' absolute 1"}
29         ]},
30     'workers': {
31         'options': "'' 'apache Workers' 'workers' workers apache.workers stacked",
32         'lines': [
33             {"name": "idle",
34              "options": "'' absolute 1 1"},
35             {"name": "busy",
36              "options": "'' absolute 1 1"}
37         ]},
38     'reqpersec': {
39         'options': "'' 'apache Lifetime Avg. Requests/s' 'requests/s' statistics apache.reqpersec area",
40         'lines': [
41             {"name": "requests_sec",
42              "options": "'' absolute 1 1000000"}
43         ]},
44     'bytespersec': {
45         'options': "'' 'apache Lifetime Avg. Response Size' 'bytes/request' statistics apache.bytesperreq area",
46         'lines': [
47             {"name": "size_sec",
48              "options": "'' absolute 8 1000000000"}
49         ]},
50     'requests': {
51         'options': "'' 'apache Requests' 'requests/s' requests apache.requests line",
52         'lines': [
53             {"name": "requests",
54              "options": "'' incremental 1 1"}
55         ]},
56     'net': {
57         'options': "'' 'apache Bandwidth' 'kilobits/s' bandwidth apache.net area",
58         'lines': [
59             {"name": "sent",
60              "options": "'' incremental 8 1"}
61         ]},
62     'connections': {
63         'options': "'' 'apache Connections' 'connections' connections apache.connections line",
64         'lines': [
65             {"name": "connections",
66              "options": "'' absolute 1 1"}
67         ]},
68     'conns_async': {
69         'options': "'' 'apache Async Connections' 'connections' connections apache.conns_async stacked",
70         'lines': [
71             {"name": "keepalive",
72              "options": "'' absolute 1 1"},
73             {"name": "closing",
74              "options": "'' absolute 1 1"},
75             {"name": "writing",
76              "options": "'' absolute 1 1"}
77         ]}
78 }
79
80
81 class Service(UrlService):
82     def __init__(self, configuration=None, name=None):
83         UrlService.__init__(self, configuration=configuration, name=name)
84         if len(self.url) == 0:
85             self.url = "http://localhost/server-status?auto"
86         self.order = ORDER
87         self.charts = CHARTS
88         self.assignment = {"BytesPerReq": 'size_req',
89                            "IdleWorkers": 'idle',
90                            "BusyWorkers": 'busy',
91                            "ReqPerSec": 'requests_sec',
92                            "BytesPerSec": 'size_sec',
93                            "Total Accesses": 'requests',
94                            "Total kBytes": 'sent',
95                            "ConnsTotal": 'connections',
96                            "ConnsAsyncKeepAlive": 'keepalive',
97                            "ConnsAsyncClosing": 'closing',
98                            "ConnsAsyncWriting": 'writing'}
99
100     def _formatted_data(self):
101         """
102         Format data received from http request
103         :return: dict
104         """
105         raw = self._get_data().split("\n")
106         data = {}
107         for row in raw:
108             tmp = row.split(":")
109             if str(tmp[0]) in self.assignment:
110                 try:
111                     data[self.assignment[tmp[0]]] = int(float(tmp[1]))
112                 except (IndexError, ValueError) as a:
113                     print(a)
114                     pass
115         if len(data) == 0:
116             return None
117         return data