priority = 60000
retries = 5
+update_every = 3
ORDER = ['cache']
CHARTS = {
def __init__(self, configuration=None, name=None):
LogService.__init__(self, configuration=configuration, name=name)
if len(self.log_path) == 0:
- self.log_path = "/var/log/httpd/cache.log"
+ self.log_path = "/var/log/apache2/cache.log"
self.order = ORDER
self.definitions = CHARTS
"""
try:
raw = self._get_data()
+ if raw is None:
+ return None
except (ValueError, AttributeError):
return None
hit = 0
miss = 0
+
for line in raw:
if "cache hit" in line:
hit += 1
elif "cache miss" in line:
miss += 1
- if hit + miss == 0:
+ total = hit + miss
+ if total == 0:
return None
- return {'hit': int(hit/float(hit+miss) * 100),
- 'miss': int(miss/float(hit+miss) * 100)}
+ hit_percent = int(hit/float(total) * 100)
+ return {'hit': hit_percent,
+ 'miss': 100 - hit_percent}
# 'chart_name_in_netdata' : [ charts['chart_name_in_netdata']['lines']['name'] ]
# }
self.log_path = ""
- self._last_line = 0
+ self._last_line = -1
# self._log_reader = None
SimpleService.__init__(self, configuration=configuration, name=name)
+ # FIXME Remove preventing of frequent log parsing
+ if self.timetable['freq'] < 3:
+ self.timetable['freq'] = 3
+ self.retries = 100000 # basically always retry
def _get_data(self):
# FIXME find faster solution of reading data. Maybe implement reading in subprocess?
# if self._log_reader.poll() is not None:
# self._log_reader = Popen(['tail', '-F', self.log_path], stdout=PIPE, stderr=STDOUT)
lines = []
- last = 0
+ last = -1
total = 0
try:
with open(self.log_path) as fp:
total += 1
except Exception as e:
msg.error(self.__module__, str(e))
- if last != 0:
+ if last != -1:
self._last_line = last
- elif self._last_line > total:
- self._last_line = 0
+ if self._last_line > total:
+ self._last_line = -1
if len(lines) != 0:
return lines
except (KeyError, TypeError):
self.error("No path to log specified. Using: '" + self.log_path + "'")
- # FIXME Remove preventing of frequent log parsing
- if self.update_every < 3:
- self.update_every = 3
-
if os.access(self.log_path, os.R_OK):
return True
else:
self.error("Cannot access file: '" + self.log_path + "'")
return False
+
+ def create(self):
+ status = SimpleService.create(self)
+ self._last_line = -1
+ return status
+