mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
cli options, fixes
This commit is contained in:
@@ -25,7 +25,7 @@ class CapsmanCollector(BaseCollector):
|
||||
remote_caps_labels = ['identity', 'version', 'base_mac', 'board', 'base_mac']
|
||||
remote_caps_records = router_metric.capsman_remote_caps_records(remote_caps_labels)
|
||||
if not remote_caps_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
remote_caps_metrics = BaseCollector.info_collector('capsman_remote_caps', 'CAPsMAN remote caps', remote_caps_records, remote_caps_labels)
|
||||
yield remote_caps_metrics
|
||||
@@ -33,7 +33,7 @@ class CapsmanCollector(BaseCollector):
|
||||
registration_labels = ['interface', 'ssid', 'mac_address', 'tx_rate', 'rx_rate', 'rx_signal', 'uptime', 'bytes']
|
||||
registration_records = router_metric.capsman_registration_table_records(registration_labels)
|
||||
if not registration_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
# calculate number of registrations per interface
|
||||
registration_per_interface = {}
|
||||
@@ -53,40 +53,28 @@ class CapsmanCollector(BaseCollector):
|
||||
dhcp_lease_labels = ['mac_address', 'host_name', 'comment']
|
||||
dhcp_lease_records = router_metric.dhcp_lease_records(dhcp_lease_labels)
|
||||
for registration_record in registration_records:
|
||||
dhcp_lease_record = next((dhcp_lease_record for dhcp_lease_record in dhcp_lease_records if dhcp_lease_record['mac_address']==registration_record['mac_address']))
|
||||
if dhcp_lease_record:
|
||||
registration_record['name'] = dhcp_lease_record.get('comment', dhcp_lease_record.get('host_name', dhcp_lease_record.get('mac_address')))
|
||||
else:
|
||||
registration_record['name'] = registration_record['mac_address']
|
||||
try:
|
||||
dhcp_lease_record = next((dhcp_lease_record for dhcp_lease_record in dhcp_lease_records if dhcp_lease_record['mac_address']==registration_record['mac_address']))
|
||||
registration_record['name'] = dhcp_lease_record.get('comment', dhcp_lease_record.get('host_name', dhcp_lease_record.get('mac_address')))
|
||||
except StopIteration:
|
||||
registration_record['name'] = f"{registration_record['mac_address']}: No DHCP registration"
|
||||
|
||||
# split out tx/rx bytes
|
||||
registration_record['tx_bytes'] = registration_record['bytes'].split(',')[0]
|
||||
registration_record['rx_bytes'] = registration_record['bytes'].split(',')[1]
|
||||
del registration_record['bytes']
|
||||
|
||||
tx_byte_metrics = BaseCollector.counter_collector('capsman_traffic_tx_bytes', 'Number of sent packet bytes', registration_records, 'tx_bytes', ['name'])
|
||||
tx_byte_metrics = BaseCollector.counter_collector('capsman_clients_tx_bytes', 'Number of sent packet bytes', registration_records, 'tx_bytes', ['name'])
|
||||
yield tx_byte_metrics
|
||||
|
||||
rx_byte_metrics = BaseCollector.counter_collector('capsman_traffic_rx_bytes', 'Number of received packet bytes', registration_records, 'rx_bytes', ['name'])
|
||||
rx_byte_metrics = BaseCollector.counter_collector('capsman_clients_rx_bytes', 'Number of received packet bytes', registration_records, 'rx_bytes', ['name'])
|
||||
yield rx_byte_metrics
|
||||
|
||||
signal_strength_metrics = BaseCollector.gauge_collector('capsman_registered_signal_strength', 'Registered devices signal strength', registration_records, 'rx_signal', ['name'])
|
||||
signal_strength_metrics = BaseCollector.gauge_collector('capsman_clients_signal_strength', 'Client devices signal strength', registration_records, 'rx_signal', ['name'])
|
||||
yield signal_strength_metrics
|
||||
|
||||
registration_metrics = BaseCollector.info_collector('capsman_registered_devices', 'Registered devices info',
|
||||
registration_metrics = BaseCollector.info_collector('capsman_clients_devices', 'Registered client devices info',
|
||||
registration_records, ['name', 'rx_signal', 'ssid', 'tx_rate', 'rx_rate', 'interface', 'mac_address', 'uptime'])
|
||||
yield registration_metrics
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class DHCPCollector(BaseCollector):
|
||||
dhcp_lease_labels = ['active_address', 'mac_address', 'host_name', 'comment', 'server', 'expires_after']
|
||||
dhcp_lease_records = router_metric.dhcp_lease_records(dhcp_lease_labels)
|
||||
if not dhcp_lease_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
# calculate number of leases per DHCP server
|
||||
dhcp_lease_servers = {}
|
||||
|
||||
@@ -23,7 +23,7 @@ class HealthCollector(BaseCollector):
|
||||
health_labels = ['voltage', 'temperature']
|
||||
health_records = router_metric.health_records(health_labels)
|
||||
if not health_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
voltage_metrics = BaseCollector.gauge_collector('system_routerboard_voltage', 'Supplied routerboard voltage', health_records, 'voltage')
|
||||
yield voltage_metrics
|
||||
|
||||
@@ -23,7 +23,7 @@ class IdentityCollector(BaseCollector):
|
||||
identity_labels = ['name']
|
||||
identity_records = router_metric.identity_records(identity_labels)
|
||||
if not identity_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
identity_metrics = BaseCollector.info_collector('system_identity', 'System identity', identity_records, identity_labels)
|
||||
yield identity_metrics
|
||||
|
||||
@@ -23,7 +23,11 @@ class InterfaceCollector(BaseCollector):
|
||||
interface_traffic_labels = ['name', 'comment', 'rx_byte', 'tx_byte', 'rx_packet', 'tx_packet', 'rx_error', 'tx_error', 'rx_drop', 'tx_drop']
|
||||
interface_traffic_records = router_metric.interface_traffic_records(interface_traffic_labels)
|
||||
if not interface_traffic_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
for interface_traffic_record in interface_traffic_records:
|
||||
if interface_traffic_record.get('comment'):
|
||||
interface_traffic_record['name'] = f"{interface_traffic_record['name']} ({interface_traffic_record['comment']})"
|
||||
|
||||
rx_byte_metric = BaseCollector.counter_collector('interface_rx_byte', 'Number of received bytes', interface_traffic_records, 'rx_byte', ['name'])
|
||||
yield rx_byte_metric
|
||||
|
||||
@@ -21,10 +21,10 @@ class MonitorCollector(BaseCollector):
|
||||
'''
|
||||
@staticmethod
|
||||
def collect(router_metric):
|
||||
monitor_labels = ['status', 'rate', 'full_duplex', 'name']
|
||||
monitor_records = router_metric.interface_monitor_records(monitor_labels)
|
||||
monitor_labels = ('status', 'rate', 'full_duplex', 'name')
|
||||
monitor_records = router_metric.interface_monitor_records(monitor_labels, include_comments = True)
|
||||
if not monitor_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
# translate records to appropriate values
|
||||
for monitor_record in monitor_records:
|
||||
|
||||
@@ -25,7 +25,7 @@ class PoolCollector(BaseCollector):
|
||||
# initialize all pool counts, including those currently not used
|
||||
pool_records = router_metric.pool_records(['name'])
|
||||
if not pool_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
pool_used_labels = ['pool']
|
||||
pool_used_counts = {pool_record['name']: 0 for pool_record in pool_records}
|
||||
|
||||
@@ -28,7 +28,7 @@ class SystemResourceCollector(BaseCollector):
|
||||
'architecture_name', 'board_name']
|
||||
resource_records = router_metric.system_resource_records(resource_labels)
|
||||
if not resource_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
# translate records to appropriate values
|
||||
translated_fields = ['uptime']
|
||||
|
||||
@@ -24,7 +24,7 @@ class RouteCollector(BaseCollector):
|
||||
route_labels = ['connect', 'dynamic', 'static', 'bgp', 'ospf']
|
||||
route_records = router_metric.route_records(route_labels)
|
||||
if not route_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
# compile total routes records
|
||||
total_routes = len(route_records)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
|
||||
import re
|
||||
from mktxp.collectors.base_collector import BaseCollector
|
||||
from mktxp.router_metric import RouterMetric
|
||||
|
||||
@@ -20,25 +21,76 @@ class WLANCollector(BaseCollector):
|
||||
'''
|
||||
@staticmethod
|
||||
def collect(router_metric):
|
||||
monitor_labels = ['channel', 'noise_floor', 'overall_tx_ccq']
|
||||
monitor_labels = ['channel', 'noise_floor', 'overall_tx_ccq', 'registered_clients']
|
||||
monitor_records = router_metric.interface_monitor_records(monitor_labels, 'wireless')
|
||||
if not monitor_records:
|
||||
return
|
||||
return range(0)
|
||||
|
||||
# sanitize records for relevant labels
|
||||
noise_floor_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('noise_floor')]
|
||||
tx_ccq_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('overall_tx_ccq')]
|
||||
registered_clients_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('registered_clients')]
|
||||
|
||||
if noise_floor_records:
|
||||
noise_floor_metrics = BaseCollector.gauge_collector('wlan_noise_floor', 'Noise floor threshold', noise_floor_records, 'noise_floor', ['channel'])
|
||||
yield noise_floor_metrics
|
||||
|
||||
if tx_ccq_records:
|
||||
overall_tx_ccq_metrics = BaseCollector.gauge_collector('wlan_overall_tx_ccq', ' Client Connection Quality for transmitting', tx_ccq_records, 'overall_tx_ccq', ['channel'])
|
||||
overall_tx_ccq_metrics = BaseCollector.gauge_collector('wlan_overall_tx_ccq', 'Client Connection Quality for transmitting', tx_ccq_records, 'overall_tx_ccq', ['channel'])
|
||||
yield overall_tx_ccq_metrics
|
||||
|
||||
if registered_clients_records:
|
||||
registered_clients_metrics = BaseCollector.gauge_collector('wlan_registered_clients', 'Number of registered clients', registered_clients_records, 'registered_clients', ['channel'])
|
||||
yield registered_clients_metrics
|
||||
|
||||
|
||||
# the client info metrics
|
||||
if router_metric.router_entry.wireless_clients:
|
||||
# TBD
|
||||
pass
|
||||
registration_labels = ['interface', 'ssid', 'mac_address', 'tx_rate', 'rx_rate', 'uptime', 'bytes', 'signal_to_noise', 'tx_ccq', 'signal_strength']
|
||||
registration_records = router_metric.wireless_registration_table_records(registration_labels)
|
||||
if not registration_records:
|
||||
return range(0)
|
||||
|
||||
dhcp_lease_labels = ['mac_address', 'host_name', 'comment']
|
||||
dhcp_lease_records = router_metric.dhcp_lease_records(dhcp_lease_labels)
|
||||
|
||||
for registration_record in registration_records:
|
||||
try:
|
||||
dhcp_lease_record = next((dhcp_lease_record for dhcp_lease_record in dhcp_lease_records if dhcp_lease_record['mac_address']==registration_record['mac_address']))
|
||||
registration_record['name'] = dhcp_lease_record.get('comment', dhcp_lease_record.get('host_name', dhcp_lease_record.get('mac_address')))
|
||||
except StopIteration:
|
||||
registration_record['name'] = registration_record['mac_address']
|
||||
|
||||
# split out tx/rx bytes
|
||||
registration_record['tx_bytes'] = registration_record['bytes'].split(',')[0]
|
||||
registration_record['rx_bytes'] = registration_record['bytes'].split(',')[1]
|
||||
|
||||
# average signal strength
|
||||
registration_record['signal_strength'] = re.search(r'-\d+', registration_record['signal_strength']).group()
|
||||
|
||||
del registration_record['bytes']
|
||||
|
||||
tx_byte_metrics = BaseCollector.counter_collector('wlan_clients_tx_bytes', 'Number of sent packet bytes', registration_records, 'tx_bytes', ['name'])
|
||||
yield tx_byte_metrics
|
||||
|
||||
rx_byte_metrics = BaseCollector.counter_collector('wlan_clients_rx_bytes', 'Number of received packet bytes', registration_records, 'rx_bytes', ['name'])
|
||||
yield rx_byte_metrics
|
||||
|
||||
signal_strength_metrics = BaseCollector.gauge_collector('wlan_clients_signal_strength', 'Average strength of the client signal recevied by AP', registration_records, 'signal_strength', ['name'])
|
||||
yield signal_strength_metrics
|
||||
|
||||
signal_to_noise_metrics = BaseCollector.gauge_collector('wlan_clients_signal_to_noise', 'Client devices signal to noise ratio', registration_records, 'signal_to_noise', ['name'])
|
||||
yield signal_to_noise_metrics
|
||||
|
||||
tx_ccq_metrics = BaseCollector.gauge_collector('wlan_clients_tx_ccq', 'Client Connection Quality (CCQ) for transmit', registration_records, 'tx_ccq', ['name'])
|
||||
yield tx_ccq_metrics
|
||||
|
||||
registration_metrics = BaseCollector.info_collector('wlan_clients_devices', 'Client devices info',
|
||||
registration_records, ['name', 'rx_signal', 'ssid', 'tx_rate', 'rx_rate', 'interface', 'mac_address', 'uptime'])
|
||||
yield registration_metrics
|
||||
|
||||
|
||||
return range(0)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user