From 7b2e18b609f683a7798f23b185eee2b1d19f3ca7 Mon Sep 17 00:00:00 2001 From: Arseniy Kuznetsov Date: Sun, 15 Jan 2023 17:25:17 +0100 Subject: [PATCH] interface monitor optimisations/wifiwave2 support --- mktxp/cli/config/_mktxp.conf | 7 +++---- mktxp/cli/config/mktxp.conf | 5 +++-- mktxp/collector/capsman_collector.py | 2 +- mktxp/collector/wlan_collector.py | 6 +++--- mktxp/datasource/capsman_ds.py | 5 +++-- mktxp/datasource/interface_ds.py | 20 ++++++++++++-------- mktxp/datasource/wireless_ds.py | 5 +++-- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/mktxp/cli/config/_mktxp.conf b/mktxp/cli/config/_mktxp.conf index add84b0..f04b45d 100644 --- a/mktxp/cli/config/_mktxp.conf +++ b/mktxp/cli/config/_mktxp.conf @@ -26,7 +26,6 @@ verbose_mode = False # Set it on for troubleshooting fetch_routers_in_parallel = False # Set to True if you want to fetch multiple routers parallel - max_worker_threads = 5 # Max number of worker threads that can fetch routers. Meaningless if fetch_routers_in_parallel is set to False - - max_scrape_duration = 10 # Max duration of individual routers' metrics collection - total_max_scrape_duration = 30 # Max overall duration of all metrics collection \ No newline at end of file + max_worker_threads = 5 # Max number of worker threads that can fetch routers (parallel fetch only) + max_scrape_duration = 10 # Max duration of individual routers' metrics collection (parallel fetch only) + total_max_scrape_duration = 30 # Max overall duration of all metrics collection (parallel fetch only) \ No newline at end of file diff --git a/mktxp/cli/config/mktxp.conf b/mktxp/cli/config/mktxp.conf index cc124da..548eb6f 100644 --- a/mktxp/cli/config/mktxp.conf +++ b/mktxp/cli/config/mktxp.conf @@ -47,6 +47,7 @@ user = True # Active Users metrics queue = True # Queues metrics - remote_dhcp_entry = None # Alternative mktxp entry for DHCP info resolution (capsman/wireless) + + remote_dhcp_entry = None # An MKTXP entry for remote DHCP info resolution (capsman/wireless) - use_comments_over_names = True # when available, forces using comments over the interfaces names \ No newline at end of file + use_comments_over_names = True # when available, forces using comments over the interfaces names diff --git a/mktxp/collector/capsman_collector.py b/mktxp/collector/capsman_collector.py index e5a02d3..caf7fba 100644 --- a/mktxp/collector/capsman_collector.py +++ b/mktxp/collector/capsman_collector.py @@ -35,7 +35,7 @@ class CapsmanCollector(BaseCollector): remote_caps_metrics = BaseCollector.info_collector('capsman_remote_caps', 'CAPsMAN remote caps', remote_caps_records, remote_caps_labels) yield remote_caps_metrics - registration_labels = ['interface', 'ssid', 'mac_address', 'tx_rate', 'rx_rate', 'rx_signal', 'uptime', 'bytes'] + registration_labels = ['interface', 'ssid', 'mac_address', 'tx_rate', 'rx_rate', 'rx_signal', 'signal','uptime', 'bytes'] registration_records = CapsmanRegistrationsMetricsDataSource.metric_records(router_entry, metric_labels = registration_labels) if registration_records: # calculate number of registrations per interface diff --git a/mktxp/collector/wlan_collector.py b/mktxp/collector/wlan_collector.py index e80db8f..47ecbce 100644 --- a/mktxp/collector/wlan_collector.py +++ b/mktxp/collector/wlan_collector.py @@ -27,7 +27,7 @@ class WLANCollector(BaseCollector): if not router_entry.config_entry.wireless: return - monitor_labels = ['channel', 'noise_floor', 'overall_tx_ccq', 'registered_clients'] + monitor_labels = ['channel', 'noise_floor', 'overall_tx_ccq', 'registered_clients', 'registered_peers'] router_entry.wifi_package = None monitor_records = InterfaceMonitorMetricsDataSource.metric_records(router_entry, metric_labels = monitor_labels, kind = WirelessMetricsDataSource.wireless_package(router_entry)) if monitor_records: @@ -50,7 +50,7 @@ class WLANCollector(BaseCollector): # the client info metrics if router_entry.config_entry.wireless_clients: - registration_labels = ['interface', 'ssid', 'mac_address', 'tx_rate', 'rx_rate', 'uptime', 'bytes', 'signal_to_noise', 'tx_ccq', 'signal_strength'] + registration_labels = ['interface', 'ssid', 'mac_address', 'tx_rate', 'rx_rate', 'uptime', 'bytes', 'signal_to_noise', 'tx_ccq', 'signal_strength', 'signal'] registration_records = WirelessMetricsDataSource.metric_records(router_entry, metric_labels = registration_labels) if registration_records: dhcp_lease_labels = ['mac_address', 'address', 'host_name', 'comment'] @@ -58,7 +58,7 @@ class WLANCollector(BaseCollector): dhcp_lease_records = DHCPMetricsDataSource.metric_records(dhcp_entry, metric_labels = dhcp_lease_labels) for registration_record in registration_records: - BaseOutputProcessor.augment_record(router_entry, registration_record, dhcp_lease_records) + BaseOutputProcessor.augment_record(router_entry, registration_record, dhcp_lease_records) tx_byte_metrics = BaseCollector.counter_collector('wlan_clients_tx_bytes', 'Number of sent packet bytes', registration_records, 'tx_bytes', ['dhcp_name']) yield tx_byte_metrics diff --git a/mktxp/datasource/capsman_ds.py b/mktxp/datasource/capsman_ds.py index 2c702d0..4cec039 100644 --- a/mktxp/datasource/capsman_ds.py +++ b/mktxp/datasource/capsman_ds.py @@ -58,10 +58,11 @@ class CapsmanRegistrationsMetricsDataSource: registration_table_path = CapsmanInfo.registration_table_path(router_entry) registration_table_records = router_entry.api_connection.router_api().get_resource(f'{registration_table_path}').get() - # With wifiwave2, Mikrotik renamed the field 'rx_signal' to 'signal' + # With wifiwave2, Mikrotik renamed the field 'rx-signal' to 'signal' + # For backward compatibility, including both variants for record in registration_table_records: if 'signal' in record: - record['rx_signal'] = record['signal'] + record['rx-signal'] = record['signal'] return BaseDSProcessor.trimmed_records(router_entry, router_records = registration_table_records, metric_labels = metric_labels, add_router_id = add_router_id) except Exception as exc: diff --git a/mktxp/datasource/interface_ds.py b/mktxp/datasource/interface_ds.py index a49f2ea..8a12cb7 100644 --- a/mktxp/datasource/interface_ds.py +++ b/mktxp/datasource/interface_ds.py @@ -38,24 +38,28 @@ class InterfaceMonitorMetricsDataSource: if metric_labels is None: metric_labels = [] try: - interfaces = router_entry.api_connection.router_api().get_resource(f'/interface/{kind}').get() - interface_names = [(interface['name'], interface.get('comment'), interface.get('running')) for interface in interfaces] + interfaces = router_entry.api_connection.router_api().get_resource(f'/interface/{kind}').call('print', {'proplist':'name,comment,running'}) interface_monitor_records = [] - for int_num, interface_name in enumerate(interface_names): + for int_num, interface in enumerate(interfaces): interface_monitor_record = {} - if not running_only or interface_name[2] == 'true': + if not running_only or interface['running'] == 'true': interface_monitor_record = router_entry.api_connection.router_api().get_resource(f'/interface/{kind}').call('monitor', {'once':'', 'numbers':f'{int_num}'})[0] else: # unless explicitly requested, no need to do a monitor call for not running interfaces - interface_monitor_record = {'name': interface_name[0], 'status': 'no-link'} + interface_monitor_record = {'name': interface['name'], 'status': 'no-link'} - if include_comments and interface_name[1]: + if include_comments and interface.get('comment'): # combines names with comments - interface_monitor_record['name'] = interface_name[1] if router_entry.config_entry.use_comments_over_names else \ - f"{interface_name[0]} ({interface_name[1]})" + interface_monitor_record['name'] = interface['comment'] if router_entry.config_entry.use_comments_over_names else \ + f"{interface['name']} ({interface['comment']})" interface_monitor_records.append(interface_monitor_record) + # With wifiwave2, Mikrotik renamed the field 'registered-clients' to 'registered-peers' + # For backward compatibility, including both variants + for interface_monitor_record in interface_monitor_records: + if 'registered-peers' in interface_monitor_record: + interface_monitor_record['registered-clients'] = interface_monitor_record['registered-peers'] return BaseDSProcessor.trimmed_records(router_entry, router_records = interface_monitor_records, metric_labels = metric_labels) except Exception as exc: print(f'Error getting {kind} interface monitor info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') diff --git a/mktxp/datasource/wireless_ds.py b/mktxp/datasource/wireless_ds.py index 8b29369..eb9bae0 100644 --- a/mktxp/datasource/wireless_ds.py +++ b/mktxp/datasource/wireless_ds.py @@ -30,10 +30,11 @@ class WirelessMetricsDataSource: wireless_package = WirelessMetricsDataSource.wireless_package(router_entry) registration_table_records = router_entry.api_connection.router_api().get_resource(f'/interface/{wireless_package}/registration-table').get() - # With wifiwave2, Mikrotik renamed the field 'signal_strength' to 'signal' + # With wifiwave2, Mikrotik renamed the field 'signal-strength' to 'signal' + # For backward compatibility, including both variants for record in registration_table_records: if 'signal' in record: - record['signal_strength'] = record['signal'] + record['signal-strength'] = record['signal'] return BaseDSProcessor.trimmed_records(router_entry, router_records = registration_table_records, metric_labels = metric_labels, add_router_id = add_router_id,) except Exception as exc: