@cryptotaxi247 / netdata-1 / commits / ff9006c5b

litespeed: use _PER_SEC values instead of TOT_

lgz committed Jun 5, 2018 at 10:24 UTC ff9006c5bf808d7fab9ea5b1fead40266fed416a
1 file changed +38 -35
python.d/litespeed.chart.py
+38 -35
@@ -6,7 +6,7 @@ import glob
6 import re
7 import os
8
9 -from collections import defaultdict
9 +from collections import defaultdict, namedtuple
10
11 from bases.FrameworkServices.SimpleService import SimpleService
12
@@ -16,7 +16,7 @@ update_every = 10
16 # charts order (can be overridden if you want less charts, or different order)
17 ORDER = [
18 'net_throughput_http', 'net_throughput_https',
19 - 'requests', 'pub_cache_hits', 'priv_cache_hits', 'static_hits']
19 + 'requests', 'pub_cache_hits', 'private_cache_hits', 'static_hits']
20
21 CHARTS = {
22 'net_throughput_http': {
@@ -36,38 +36,51 @@ CHARTS = {
36 'requests': {
37 'options': [None, 'Requests', 'req/s', 'requests', 'litespeed.requests', 'line'],
38 'lines': [
39 - ["requests", None, "incremental"]
39 + ["requests", None, "absolute", 1, 100]
40 ]},
41 'pub_cache_hits': {
42 - 'options': [None, 'Public Cache Hits', 'hits/s', 'cache', 'litespeed.pub_cache', 'line'],
42 + 'options': [None, 'Public Cache Hits', 'hits/s', 'cache', 'litespeed.cache', 'line'],
43 'lines': [
44 - ["pub_cache_hits", "hits", "incremental"]
44 + ["pub_cache_hits", "hits", "absolute", 1, 100]
45 ]},
46 - 'priv_cache_hits': {
47 - 'options': [None, 'Private Cache Hits', 'hits/s', 'cache', 'litespeed.priv_cache', 'line'],
46 + 'private_cache_hits': {
47 + 'options': [None, 'Private Cache Hits', 'hits/s', 'cache', 'litespeed.cache', 'line'],
48 'lines': [
49 - ["priv_cache_hits", "hits", "incremental"]
49 + ["private_cache_hits", "hits", "absolute", 1, 100]
50 ]},
51 'static_hits': {
52 'options': [None, 'Static Hits', 'hits/s', 'static', 'litespeed.static', 'line'],
53 'lines': [
54 - ["static_hits", "hits", "incremental"]
54 + ["static_hits", "hits", "absolute", 1, 100]
55 ]},
56 }
57
58 -KEYS = [
59 - ('BPS_IN', 'bps_in'),
60 - ('BPS_OUT', 'bps_out'),
61 - ('SSL_BPS_IN', 'ssl_bps_in'),
62 - ('SSL_BPS_OUT', 'ssl_bps_out'),
63 - ('TOT_REQS', 'requests'),
64 - ('TOTAL_PUB_CACHE_HITS', 'pub_cache_hits'),
65 - ('TOTAL_PRIVATE_CACHE_HITS', 'priv_cache_hits'),
66 - ('TOTAL_STATIC_HITS', 'static_hits'),
58 +t = namedtuple("T", ["key", "id", "mul"])
59 +
60 +T = [
61 + t("BPS_IN", "bps_in", 1),
62 + t("BPS_OUT", "bps_out", 1),
63 + t("SSL_BPS_IN", "ssl_bps_in", 1),
64 + t("SSL_BPS_OUT", "ssl_bps_out", 1),
65 + t("REQ_PER_SEC", "requests", 100),
66 + t("PUB_CACHE_HITS_PER_SEC", "pub_cache_hits", 100),
67 + t("PRIVATE_CACHE_HITS_PER_SEC", "private_cache_hits", 100),
68 + t("STATIC_HITS_PER_SEC", "static_hits", 100),
69 ]
70
71 RE = re.compile(r'([A-Z_]+): ([0-9.]+)')
72
73 +ZERO_DATA = {
74 + "bps_in": 0,
75 + "bps_out": 0,
76 + "ssl_bps_in": 0,
77 + "ssl_bps_out": 0,
78 + "requests": 0,
79 + "pub_cache_hits": 0,
80 + "private_cache_hits": 0,
81 + "static_hits": 0,
82 + }
83 +
84
85 class DataFile:
86 def __init__(self, abs_path):
@@ -88,16 +101,6 @@ class Service(SimpleService):
101 self.definitions = CHARTS
102 self.path = self.configuration.get('path')
103 self.files = list()
91 - self.data = {
92 - "bps_in": 0,
93 - "bps_out": 0,
94 - "ssl_bps_in": 0,
95 - "ssl_bps_out": 0,
96 - "requests": 0,
97 - "pub_cache_hits": 0,
98 - "priv_cache_hits": 0,
99 - "static_hits": 0,
100 - }
104
105 def check(self):
106 if not self.path:
@@ -139,10 +142,10 @@ class Service(SimpleService):
142 else:
143 parse_file(data, lines)
144
142 - if data:
143 - self.data = dict(data)
144 -
145 - return self.data
145 + if not data:
146 + self.debug('"rtreport" files have not been updated, returning zero values')
147 + return ZERO_DATA
148 + return dict(data)
149
150
151 def parse_file(data, lines):
@@ -150,9 +153,9 @@ def parse_file(data, lines):
153 if not line.startswith(("BPS_IN", "REQ_RATE []")):
154 continue
155 m = dict(RE.findall(line))
153 - for k, d in KEYS:
154 - if k in m:
155 - data[d] += int(m[k])
156 + for v in T:
157 + if v.key in m:
158 + data[v.id] += float(m[v.key]) * v.mul
159
160
161 def is_readable_file(v):