@cryptotaxi247 / netdata-1 / commits / 5f5513931

litespeed: do not check if file was changed on every iteration

lgz committed Jun 5, 2018 at 11:01 UTC 5f551393185aabba04e5643719e31c3b4529b80b
1 file changed +7 -24
python.d/litespeed.chart.py
+7 -24
@@ -6,7 +6,7 @@ import glob
6 import re
7 import os
8
9 -from collections import defaultdict, namedtuple
9 +from collections import namedtuple
10
11 from bases.FrameworkServices.SimpleService import SimpleService
12
@@ -36,14 +36,14 @@ CHARTS = {
36 ]},
37 'connections_http': {
38 'options': [
39 - None, 'Connections HTTP', 'conns', 'connections', 'litespeed.connections', 'stack'],
39 + None, 'Connections HTTP', 'conns', 'connections', 'litespeed.connections', 'stacked'],
40 'lines': [
41 ["conn_free", "free", "absolute"],
42 ["conn_used", "used", "absolute"]
43 ]},
44 'connections_https': {
45 'options': [
46 - None, 'Connections HTTPS', 'conns', 'connections', 'litespeed.connections', 'stack'],
46 + None, 'Connections HTTPS', 'conns', 'connections', 'litespeed.connections', 'stacked'],
47 'lines': [
48 ["ssl_conn_free", "free", "absolute"],
49 ["ssl_conn_used", "used", "absolute"]
@@ -105,18 +105,6 @@ ZERO_DATA = {
105 }
106
107
108 -class DataFile:
109 - def __init__(self, abs_path):
110 - self.path = abs_path
111 - self.mtime = 0
112 -
113 - def is_updated(self):
114 - o = self.mtime
115 - n = os.stat(self.path).st_mtime
116 - self.mtime = n
117 - return o != n
118 -
119 -
108 class Service(SimpleService):
109 def __init__(self, configuration=None, name=None):
110 SimpleService.__init__(self, configuration=configuration, name=name)
@@ -142,7 +130,7 @@ class Service(SimpleService):
130 if not is_readable_file(f):
131 self.error("{0} is not readable".format(f))
132 continue
145 - self.files.append(DataFile(f))
133 + self.files.append(f)
134
135 return bool(self.files)
136
@@ -151,13 +139,11 @@ class Service(SimpleService):
139 Format data received from http request
140 :return: dict
141 """
154 - data = defaultdict(int)
142 + data = dict(ZERO_DATA)
143
144 for f in self.files:
145 try:
158 - if not f.is_updated():
159 - continue
160 - with open(f.path) as b:
146 + with open(f) as b:
147 lines = b.readlines()
148 except (OSError, IOError) as err:
149 self.error(err)
@@ -165,10 +151,7 @@ class Service(SimpleService):
151 else:
152 parse_file(data, lines)
153
168 - if not data:
169 - self.debug('"rtreport" files have not been updated, returning zero values')
170 - return ZERO_DATA
171 - return dict(data)
154 + return data
155
156
157 def parse_file(data, lines):