]> arthur.barton.de Git - netdata.git/blob - python.d/apache.chart.py
fixed some issues from previous commits
[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     # url = "http://localhost/server-status?auto"
83     url = "http://www.apache.org/server-status?auto"
84     order = ORDER
85     charts = CHARTS
86     assignment = {"BytesPerReq": 'size_req',
87                   "IdleWorkers": 'idle',
88                   "BusyWorkers": 'busy',
89                   "ReqPerSec": 'requests_sec',
90                   "BytesPerSec": 'size_sec',
91                   "Total Accesses": 'requests',
92                   "Total kBytes": 'sent',
93                   "ConnsTotal": 'connections',
94                   "ConnsAsyncKeepAlive": 'keepalive',
95                   "ConnsAsyncClosing": 'closing',
96                   "ConnsAsyncWriting": 'writing'}
97
98     def _formatted_data(self):
99         """
100         Format data received from http request
101         :return: dict
102         """
103         raw = self._get_data().split("\n")
104         data = {}
105         for row in raw:
106             tmp = row.split(":")
107             if str(tmp[0]) in self.assignment:
108                 try:
109                     data[self.assignment[tmp[0]]] = int(float(tmp[1]))
110                 except (IndexError, ValueError) as a:
111                     print(a)
112                     pass
113         if len(data) == 0:
114             return None
115         return data