]> arthur.barton.de Git - netdata.git/blob - python.d/phpfpm.chart.py
Merge pull request #665 from paulfantom/master
[netdata.git] / python.d / phpfpm.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: PHP-FPM 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 = 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/status'
18 # }}
19
20 # charts order (can be overridden if you want less charts, or different order)
21 ORDER = ['connections', 'requests', 'performance']
22
23 CHARTS = {
24     'connections': {
25         'options': [None, 'PHP-FPM Active Connections', 'connections', 'phpfpm', 'phpfpm.connections', 'line'],
26         'lines': [
27             ["active"],
28             ["maxActive", 'max active'],
29             ["idle"]
30         ]},
31     'requests': {
32         'options': [None, 'PHP-FPM Requests', 'requests/s', 'phpfpm', 'phpfpm.requests', 'line'],
33         'lines': [
34             ["requests", None, "incremental"]
35         ]},
36     'performance': {
37         'options': [None, 'PHP-FPM Performance', 'status', 'phpfpm', 'phpfpm.performance', 'line'],
38         'lines': [
39             ["reached", 'max children reached'],
40             ["slow", 'slow requests']
41         ]}
42 }
43
44
45 class Service(UrlService):
46     def __init__(self, configuration=None, name=None):
47         UrlService.__init__(self, configuration=configuration, name=name)
48         if len(self.url) == 0:
49             self.url = "http://localhost/status"
50         self.order = ORDER
51         self.definitions = CHARTS
52         self.assignment = {"active processes": 'active',
53                            "max active processes": 'maxActive',
54                            "idle processes": 'idle',
55                            "accepted conn": 'requests',
56                            "max children reached": 'reached',
57                            "slow requests": 'slow'}
58
59     def _get_data(self):
60         """
61         Format data received from http request
62         :return: dict
63         """
64         try:
65             raw = self._get_raw_data().split('\n')
66         except AttributeError:
67             return None
68         data = {}
69         for row in raw:
70             tmp = row.split(":")
71             if str(tmp[0]) in self.assignment:
72                 try:
73                     data[self.assignment[tmp[0]]] = int(tmp[1])
74                 except (IndexError, ValueError):
75                     pass
76         if len(data) == 0:
77             return None
78         return data