summaryrefslogtreecommitdiffstats
path: root/python.d/phpfpm.chart.py
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2016-11-23 15:49:10 +0000
committerFederico Ceratto <federico.ceratto@gmail.com>2016-11-23 15:49:10 +0000
commit87649cf32bd0e14d5a903fb85b01e9f41a253540 (patch)
treebbefda6dac074aeb87529592e8e5064f69cbe024 /python.d/phpfpm.chart.py
parentImported Upstream version 1.3.0+dfsg (diff)
downloadnetdata-87649cf32bd0e14d5a903fb85b01e9f41a253540.tar.xz
netdata-87649cf32bd0e14d5a903fb85b01e9f41a253540.zip
New upstream version 1.4.0+dfsgupstream/1.4.0+dfsg
Diffstat (limited to '')
-rwxr-xr-xpython.d/phpfpm.chart.py59
1 files changed, 55 insertions, 4 deletions
diff --git a/python.d/phpfpm.chart.py b/python.d/phpfpm.chart.py
index d1791d42e..d4168cc11 100755
--- a/python.d/phpfpm.chart.py
+++ b/python.d/phpfpm.chart.py
@@ -3,6 +3,7 @@
# Author: Pawel Krupa (paulfantom)
from base import UrlService
+import json
# default module values (can be overridden per job in `config`)
# update_every = 2
@@ -14,11 +15,11 @@ retries = 60
# 'update_every': update_every,
# 'retries': retries,
# 'priority': priority,
-# 'url': 'http://localhost/status'
+# 'url': 'http://localhost/status?full&json'
# }}
# charts order (can be overridden if you want less charts, or different order)
-ORDER = ['connections', 'requests', 'performance']
+ORDER = ['connections', 'requests', 'performance', 'request_duration', 'request_cpu', 'request_mem']
CHARTS = {
'connections': {
@@ -38,6 +39,24 @@ CHARTS = {
'lines': [
["reached", 'max children reached'],
["slow", 'slow requests']
+ ]},
+ 'request_duration': {
+ 'options': [None, 'PHP-FPM Request Duration', 'milliseconds', 'phpfpm', 'phpfpm.request_duration', 'line'],
+ 'lines': [
+ ["maxReqDur", 'max request duration'],
+ ["avgReqDur", 'average request duration']
+ ]},
+ 'request_cpu': {
+ 'options': [None, 'PHP-FPM Request CPU', 'percent', 'phpfpm', 'phpfpm.request_cpu', 'line'],
+ 'lines': [
+ ["maxReqCPU", 'max request cpu'],
+ ["avgReqCPU", 'average request cpu']
+ ]},
+ 'request_mem': {
+ 'options': [None, 'PHP-FPM Request Memory', 'kilobytes', 'phpfpm', 'phpfpm.request_mem', 'line'],
+ 'lines': [
+ ["maxReqMem", 'max request memory'],
+ ["avgReqMem", 'average request memory']
]}
}
@@ -46,7 +65,7 @@ class Service(UrlService):
def __init__(self, configuration=None, name=None):
UrlService.__init__(self, configuration=configuration, name=name)
if len(self.url) == 0:
- self.url = "http://localhost/status"
+ self.url = "http://localhost/status?full&json"
self.order = ORDER
self.definitions = CHARTS
self.assignment = {"active processes": 'active',
@@ -55,6 +74,9 @@ class Service(UrlService):
"accepted conn": 'requests',
"max children reached": 'reached',
"slow requests": 'slow'}
+ self.proc_assignment = {"request duration": 'ReqDur',
+ "last request cpu": 'ReqCPU',
+ "last request memory": 'ReqMem'}
def _get_data(self):
"""
@@ -62,9 +84,38 @@ class Service(UrlService):
:return: dict
"""
try:
- raw = self._get_raw_data().split('\n')
+ raw = self._get_raw_data()
except AttributeError:
return None
+
+ if '?json' in self.url or '&json' in self.url:
+ try:
+ raw_json = json.loads(raw)
+ except ValueError:
+ return None
+ data = {self.assignment[k]: v for k, v in raw_json.items() if k in self.assignment}
+ if '&full' in self.url or '?full' in self.url:
+ c = 0
+ for proc in raw_json['processes']:
+ if proc['state'] != 'Idle':
+ continue
+ c += 1
+ for k, v in self.proc_assignment.items():
+ d = proc[k]
+ if v == 'ReqDur':
+ d = d/1000
+ if v == 'ReqMem':
+ d = d/1024
+ if 'max' + v not in data or data['max' + v] < d:
+ data['max' + v] = d
+ if 'avg' + v not in data:
+ data['avg' + v] = 0
+ data['avg' + v] = (data['avg' + v] + d) / c
+ if len(data) == 0:
+ return None
+ return data
+
+ raw = raw.split('\n')
data = {}
for row in raw:
tmp = row.split(":")