-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from imposibrus/main
Add DNS server stats collector
- Loading branch information
Showing
9 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# coding=utf8 | ||
# Copyright (c) 2020 Arseniy Kuznetsov | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
|
||
from mktxp.cli.config.config import MKTXPConfigKeys | ||
from mktxp.collector.base_collector import BaseCollector | ||
from mktxp.datasource.dns_ds import DNSDataSource | ||
|
||
|
||
class DNSCollector(BaseCollector): | ||
'''Dns Collector''' | ||
|
||
@staticmethod | ||
def collect(router_entry): | ||
allowed_properties = {'cache_size', 'cache_used'} | ||
if not router_entry.config_entry.dns: | ||
return | ||
|
||
record = DNSDataSource.metric_records(router_entry) | ||
|
||
if not record: | ||
return | ||
|
||
keys = list(record.keys()) | ||
metrics = [] | ||
|
||
for key in keys: | ||
if key not in allowed_properties: | ||
continue | ||
|
||
metric_record = { | ||
MKTXPConfigKeys.ROUTERBOARD_NAME: router_entry.router_id[MKTXPConfigKeys.ROUTERBOARD_NAME], | ||
MKTXPConfigKeys.ROUTERBOARD_ADDRESS: router_entry.router_id[MKTXPConfigKeys.ROUTERBOARD_ADDRESS], | ||
'property': key, | ||
'value': int(record[key]) * 1024 | ||
} | ||
metrics.append(metric_record) | ||
|
||
yield BaseCollector.gauge_collector( | ||
'dns_info', | ||
'DNS info', | ||
metrics, | ||
'value', | ||
metric_labels=['property'] | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# coding=utf8 | ||
# Copyright (c) 2020 Arseniy Kuznetsov | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
|
||
from mktxp.datasource.base_ds import BaseDSProcessor | ||
|
||
|
||
class DNSDataSource: | ||
def metric_records(router_entry): | ||
try: | ||
router_records = router_entry.api_connection.router_api().get_resource('/ip/dns').get() | ||
dns_records = BaseDSProcessor.trimmed_records(router_entry, router_records=router_records) | ||
return dns_records[0] if dns_records else None | ||
except Exception as exc: | ||
print(f'Error getting DNS info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') | ||
return None |
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
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
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