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