Last active
August 23, 2019 10:21
-
-
Save RouNNdeL/28bc7f7cf3092c936d0d0073ea8b87f2 to your computer and use it in GitHub Desktop.
dnsmasq python.d plugin for netdata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bases.FrameworkServices.LogService import LogService | |
import os | |
ORDER = ['dns_query'] | |
CHARTS = { | |
"dns_query": { | |
'options': [None, 'DNS Queries', 'responses/s', 'responses', 'dnsmasq_log.dns_query', 'line'], | |
'lines': [ | |
['successful_query', 'success', 'absolute'], | |
['query_errors', 'error', 'absolute'], | |
['chached_query', 'cached', 'absolute'], | |
] | |
} | |
} | |
import re | |
REGEX_SUCCESS = r"reply \S* is [\d.:]+" | |
REGEX_ERROR = r"reply \S* is NXDOMAIN" | |
REGEX_CACHED = r"cached \S* is" | |
class Service(LogService): | |
def __init__(self, configuration=None, name=None): | |
LogService.__init__(self, configuration=configuration, name=name) | |
self.order = ORDER | |
self.definitions = CHARTS | |
self.configuration = configuration | |
self.log_path = self.configuration.get('path') | |
def check(self): | |
if not (self._find_recent_log_file() and os.access(self.log_path, os.R_OK)): | |
self.error('{log_file} not readable or not exist'.format(log_file=self.log_path)) | |
return False | |
if not os.path.getsize(self.log_path): | |
self.error('{log_file} is empty'.format(log_file=self.log_path)) | |
return False | |
return True | |
def _get_data(self): | |
lines = self._get_raw_data() | |
success = 0 | |
error = 0 | |
cached = 0 | |
for line in lines: | |
success += 1 if re.search(REGEX_SUCCESS, line) is not None else 0 | |
error += 1 if re.search(REGEX_ERROR, line) is not None else 0 | |
cached += 1 if re.search(REGEX_CACHED, line) is not None else 0 | |
return {'successful_query': success, | |
'query_errors': error, | |
'chached_query': cached} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dnsmasq_query: | |
name: "log" | |
path: "/var/log/dnsmasq/query.log" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment