Collector registry, fixes/optimizations

This commit is contained in:
Arseniy Kuznetsov
2021-02-14 09:03:08 +01:00
parent 6533a20d47
commit df84ada9c7
28 changed files with 237 additions and 234 deletions

View File

@@ -46,7 +46,7 @@ class BandwidthCollector(BaseCollector):
yield latency_metrics
ts = datetime.now().timestamp()
if (ts - self.last_call_timestamp) > config_handler._entry().bandwidth_test_interval:
if (ts - self.last_call_timestamp) > config_handler.system_entry().bandwidth_test_interval:
self.pool.apply_async(BandwidthCollector.bandwidth_worker, callback=get_result)
self.last_call_timestamp = ts

View File

@@ -13,7 +13,7 @@
from mktxp.cli.config.config import MKTXPConfigKeys
from mktxp.processor.output import BaseOutputProcessor
from mktxp.flow.processor.output import BaseOutputProcessor
from mktxp.collector.base_collector import BaseCollector
from mktxp.datasource.dhcp_ds import DHCPMetricsDataSource
from mktxp.datasource.capsman_ds import CapsmanCapsMetricsDataSource, CapsmanRegistrationsMetricsDataSource
@@ -24,6 +24,9 @@ class CapsmanCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.capsman:
return
remote_caps_labels = ['identity', 'version', 'base_mac', 'board', 'base_mac']
remote_caps_records = CapsmanCapsMetricsDataSource.metric_records(router_entry, metric_labels = remote_caps_labels)
if remote_caps_records:

View File

@@ -22,6 +22,9 @@ class DHCPCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.dhcp:
return
dhcp_lease_labels = ['active_address', 'address', 'mac_address', 'host_name', 'comment', 'server', 'expires_after']
dhcp_lease_records = DHCPMetricsDataSource.metric_records(router_entry, metric_labels = dhcp_lease_labels)
if dhcp_lease_records:

View File

@@ -22,19 +22,22 @@ class FirewallCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.firewall:
return
# initialize all pool counts, including those currently not used
firewall_labels = ['chain', 'action', 'bytes', 'comment']
firewall_labels = ['chain', 'action', 'bytes', 'comment', 'log']
firewall_filter_records = FirewallMetricsDataSource.metric_records(router_entry, metric_labels = firewall_labels)
if firewall_filter_records:
metris_records = [FirewallCollector.metric_record(router_entry, record) for record in firewall_filter_records]
firewall_filter_metrics = BaseCollector.counter_collector('firewall_filter', 'Total amount of bytes matched by firewall rules', metris_records, 'bytes', ['name'])
firewall_filter_metrics = BaseCollector.counter_collector('firewall_filter', 'Total amount of bytes matched by firewall rules', metris_records, 'bytes', ['name', 'log'])
yield firewall_filter_metrics
firewall_raw_records = FirewallMetricsDataSource.metric_records(router_entry, metric_labels = firewall_labels, raw = True)
if firewall_raw_records:
metris_records = [FirewallCollector.metric_record(router_entry, record) for record in firewall_raw_records]
firewall_raw_metrics = BaseCollector.counter_collector('firewall_raw', 'Total amount of bytes matched by raw firewall rules', metris_records, 'bytes', ['name'])
firewall_raw_metrics = BaseCollector.counter_collector('firewall_raw', 'Total amount of bytes matched by raw firewall rules', metris_records, 'bytes', ['name', 'log'])
yield firewall_raw_metrics
# Helpers
@@ -44,4 +47,4 @@ class FirewallCollector(BaseCollector):
bytes = firewall_record['bytes']
return {MKTXPConfigKeys.ROUTERBOARD_NAME: router_entry.router_id[MKTXPConfigKeys.ROUTERBOARD_NAME],
MKTXPConfigKeys.ROUTERBOARD_ADDRESS: router_entry.router_id[MKTXPConfigKeys.ROUTERBOARD_ADDRESS],
'name': name, 'bytes': bytes}
'name': name, 'log': firewall_record['log'], 'bytes': bytes}

View File

@@ -21,6 +21,9 @@ class InterfaceCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.interface:
return
interface_traffic_labels = ['name', 'comment', 'rx_byte', 'tx_byte', 'rx_packet', 'tx_packet', 'rx_error', 'tx_error', 'rx_drop', 'tx_drop']
interface_traffic_records = InterfaceTrafficMetricsDataSource.metric_records(router_entry, metric_labels = interface_traffic_labels)

View File

@@ -13,7 +13,7 @@
from mktxp.collector.base_collector import BaseCollector
from mktxp.processor.output import BaseOutputProcessor
from mktxp.flow.processor.output import BaseOutputProcessor
from mktxp.datasource.interface_ds import InterfaceMonitorMetricsDataSource
@@ -22,6 +22,9 @@ class MonitorCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.monitor:
return
monitor_labels = ('status', 'rate', 'full_duplex', 'name')
monitor_records = InterfaceMonitorMetricsDataSource.metric_records(router_entry, metric_labels = monitor_labels, include_comments = True)
if monitor_records:

View File

@@ -22,6 +22,9 @@ class PoolCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.pool:
return
# initialize all pool counts, including those currently not used
pool_records = PoolMetricsDataSource.metric_records(router_entry, metric_labels = ['name'])
if pool_records:

View File

@@ -13,7 +13,7 @@
from mktxp.collector.base_collector import BaseCollector
from mktxp.processor.output import BaseOutputProcessor
from mktxp.flow.processor.output import BaseOutputProcessor
from mktxp.datasource.system_resource_ds import SystemResourceMetricsDataSource

View File

@@ -22,6 +22,9 @@ class RouteCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.route:
return
route_labels = ['connect', 'dynamic', 'static', 'bgp', 'ospf']
route_records = RouteMetricsDataSource.metric_records(router_entry, metric_labels = route_labels)
if route_records:

View File

@@ -12,7 +12,7 @@
## GNU General Public License for more details.
from mktxp.processor.output import BaseOutputProcessor
from mktxp.flow.processor.output import BaseOutputProcessor
from mktxp.collector.base_collector import BaseCollector
from mktxp.datasource.dhcp_ds import DHCPMetricsDataSource
from mktxp.datasource.wireless_ds import WirelessMetricsDataSource
@@ -24,6 +24,9 @@ class WLANCollector(BaseCollector):
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.wireless:
return
monitor_labels = ['channel', 'noise_floor', 'overall_tx_ccq', 'registered_clients']
monitor_records = InterfaceMonitorMetricsDataSource.metric_records(router_entry, metric_labels = monitor_labels, kind = 'wireless')
if monitor_records: