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