interface monitor optimisations/wifiwave2 support

This commit is contained in:
Arseniy Kuznetsov
2023-01-15 17:25:17 +01:00
parent 3bc14a6197
commit 7b2e18b609
7 changed files with 28 additions and 22 deletions

View File

@@ -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
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)

View File

@@ -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
use_comments_over_names = True # when available, forces using comments over the interfaces names

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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}')

View File

@@ -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: