Skip to content

Commit

Permalink
Merge pull request #203 from imposibrus/main
Browse files Browse the repository at this point in the history
Add DNS server stats collector
  • Loading branch information
akpw authored Dec 5, 2024
2 parents 76c8a3e + 5eb8d2b commit 94fb40d
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The default configuration file comes with a sample configuration, making it easy
pool = True # IPv4 Pool metrics
firewall = True # IPv4 Firewall rules traffic metrics
neighbor = True # IPv4 Reachable Neighbors
dns = False # DNS stats
ipv6_route = False # IPv6 Routes metrics
ipv6_pool = False # IPv6 Pool metrics
Expand Down Expand Up @@ -473,4 +474,4 @@ mktxp is running as pid 36704

**Running Tests**
- TDB
- Run via: `$ python setup.py test`
- Run via: `$ python setup.py test`
1 change: 1 addition & 0 deletions deploy/kubernetes/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ stringData:
pool = True # IPv4 Pool metrics
firewall = True # IPv4 Firewall rules traffic metrics
neighbor = True # IPv4 Reachable Neighbors
dns = False # DNS stats
ipv6_route = False # IPv6 Routes metrics
ipv6_pool = False # IPv6 Pool metrics
Expand Down
6 changes: 4 additions & 2 deletions mktxp/cli/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CollectorKeys:
HEALTH_COLLECTOR = 'HealthCollector'
PUBLIC_IP_ADDRESS_COLLECTOR = 'PublicIPAddressCollector'
NEIGHBOR_COLLECTOR = 'NeighborCollector'
DNS_COLLECTOR = 'DNSCollector'
PACKAGE_COLLECTOR = 'PackageCollector'
DHCP_COLLECTOR = 'DHCPCollector'
POOL_COLLECTOR = 'PoolCollector'
Expand Down Expand Up @@ -82,6 +83,7 @@ class MKTXPConfigKeys:
FE_DHCP_POOL_KEY = 'pool'
FE_FIREWALL_KEY = 'firewall'
FE_NEIGHBOR_KEY = 'neighbor'
FE_DNS_KEY = 'dns'

FE_IPV6_ROUTE_KEY = 'ipv6_route'
FE_IPV6_DHCP_POOL_KEY = 'ipv6_pool'
Expand Down Expand Up @@ -162,7 +164,7 @@ class MKTXPConfigKeys:

BOOLEAN_KEYS_NO = {ENABLED_KEY, SSL_KEY, NO_SSL_CERTIFICATE, FE_CHECK_FOR_UPDATES, FE_KID_CONTROL_DEVICE, FE_KID_CONTROL_DYNAMIC,
SSL_CERTIFICATE_VERIFY, FE_IPV6_ROUTE_KEY, FE_IPV6_DHCP_POOL_KEY, FE_IPV6_FIREWALL_KEY, FE_IPV6_NEIGHBOR_KEY, FE_CONNECTION_STATS_KEY, FE_BGP_KEY,
FE_IPSEC_KEY, FE_LTE_KEY, FE_SWITCH_PORT_KEY, FE_ROUTING_STATS_KEY, FE_CERTIFICATE_KEY}
FE_IPSEC_KEY, FE_LTE_KEY, FE_SWITCH_PORT_KEY, FE_ROUTING_STATS_KEY, FE_CERTIFICATE_KEY, FE_DNS_KEY}

# Feature keys enabled by default
BOOLEAN_KEYS_YES = {PLAINTEXT_LOGIN_KEY, FE_DHCP_KEY, FE_PACKAGE_KEY, FE_DHCP_LEASE_KEY, FE_IP_CONNECTIONS_KEY, FE_INTERFACE_KEY,
Expand Down Expand Up @@ -192,7 +194,7 @@ class ConfigEntry:
MKTXPConfigKeys.FE_MONITOR_KEY, MKTXPConfigKeys.FE_WIRELESS_KEY, MKTXPConfigKeys.FE_WIRELESS_CLIENTS_KEY,
MKTXPConfigKeys.FE_IP_CONNECTIONS_KEY, MKTXPConfigKeys.FE_CONNECTION_STATS_KEY, MKTXPConfigKeys.FE_CAPSMAN_KEY, MKTXPConfigKeys.FE_CAPSMAN_CLIENTS_KEY, MKTXPConfigKeys.FE_POE_KEY,
MKTXPConfigKeys.FE_NETWATCH_KEY, MKTXPConfigKeys.MKTXP_USE_COMMENTS_OVER_NAMES, MKTXPConfigKeys.FE_PUBLIC_IP_KEY,
MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_FIREWALL_KEY, MKTXPConfigKeys.FE_NEIGHBOR_KEY,
MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_FIREWALL_KEY, MKTXPConfigKeys.FE_NEIGHBOR_KEY, MKTXPConfigKeys.FE_DNS_KEY,
MKTXPConfigKeys.FE_IPV6_ROUTE_KEY, MKTXPConfigKeys.FE_IPV6_DHCP_POOL_KEY, MKTXPConfigKeys.FE_IPV6_FIREWALL_KEY, MKTXPConfigKeys.FE_IPV6_NEIGHBOR_KEY,
MKTXPConfigKeys.FE_USER_KEY, MKTXPConfigKeys.FE_QUEUE_KEY, MKTXPConfigKeys.FE_REMOTE_DHCP_ENTRY, MKTXPConfigKeys.FE_REMOTE_CAPSMAN_ENTRY, MKTXPConfigKeys.FE_CHECK_FOR_UPDATES, MKTXPConfigKeys.FE_BGP_KEY,
MKTXPConfigKeys.FE_KID_CONTROL_DEVICE, MKTXPConfigKeys.FE_KID_CONTROL_DYNAMIC, MKTXPConfigKeys.FE_LTE_KEY, MKTXPConfigKeys.FE_IPSEC_KEY, MKTXPConfigKeys.FE_SWITCH_PORT_KEY,
Expand Down
1 change: 1 addition & 0 deletions mktxp/cli/config/mktxp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
pool = True # IPv4 Pool metrics
firewall = True # IPv4 Firewall rules traffic metrics
neighbor = True # IPv4 Reachable Neighbors
dns = False # DNS stats

ipv6_route = False # IPv6 Routes metrics
ipv6_pool = False # IPv6 Pool metrics
Expand Down
55 changes: 55 additions & 0 deletions mktxp/collector/dns_collector.py
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']
)
26 changes: 26 additions & 0 deletions mktxp/datasource/dns_ds.py
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
2 changes: 2 additions & 0 deletions mktxp/flow/collector_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from mktxp.collector.lte_collector import LTECollector
from mktxp.collector.switch_collector import SwitchPortCollector
from mktxp.collector.certificate_collector import CertificateCollector
from mktxp.collector.dns_collector import DNSCollector

class CollectorRegistry:
''' MKTXP Collectors Registry
Expand All @@ -59,6 +60,7 @@ def __init__(self):
self.register(CollectorKeys.PUBLIC_IP_ADDRESS_COLLECTOR, PublicIPAddressCollector.collect)

self.register(CollectorKeys.NEIGHBOR_COLLECTOR, NeighborCollector.collect)
self.register(CollectorKeys.DNS_COLLECTOR, DNSCollector.collect)

self.register(CollectorKeys.PACKAGE_COLLECTOR, PackageCollector.collect)
self.register(CollectorKeys.DHCP_COLLECTOR, DHCPCollector.collect)
Expand Down
1 change: 1 addition & 0 deletions mktxp/flow/router_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, router_name):
CollectorKeys.HEALTH_COLLECTOR: 0,
CollectorKeys.PUBLIC_IP_ADDRESS_COLLECTOR: 0,
CollectorKeys.NEIGHBOR_COLLECTOR: 0,
CollectorKeys.DNS_COLLECTOR: 0,
CollectorKeys.PACKAGE_COLLECTOR: 0,
CollectorKeys.DHCP_COLLECTOR: 0,
CollectorKeys.POOL_COLLECTOR: 0,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='mktxp',
version='1.2.9',
version='1.2.10',

url='https://github.com/akpw/mktxp',

Expand Down

0 comments on commit 94fb40d

Please sign in to comment.