mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
feat: adds additional metrics for DHCP: last-seen, client-id, active-mac-address
This commit is contained in:
@@ -25,7 +25,7 @@ class DHCPCollector(BaseCollector):
|
|||||||
if not router_entry.config_entry.dhcp:
|
if not router_entry.config_entry.dhcp:
|
||||||
return
|
return
|
||||||
|
|
||||||
dhcp_lease_labels = ['active_address', 'address', 'mac_address', 'host_name', 'comment', 'server', 'expires_after']
|
dhcp_lease_labels = ['active_address', 'address', 'mac_address', 'host_name', 'comment', 'server', 'expires_after', 'last_seen', 'client_id', 'active_mac_address']
|
||||||
dhcp_lease_records = DHCPMetricsDataSource.metric_records(router_entry, metric_labels = dhcp_lease_labels)
|
dhcp_lease_records = DHCPMetricsDataSource.metric_records(router_entry, metric_labels = dhcp_lease_labels)
|
||||||
if dhcp_lease_records:
|
if dhcp_lease_records:
|
||||||
# calculate number of leases per DHCP server
|
# calculate number of leases per DHCP server
|
||||||
@@ -56,4 +56,3 @@ class DHCPCollector(BaseCollector):
|
|||||||
#if router_entry.config_entry.dhcp_lease:
|
#if router_entry.config_entry.dhcp_lease:
|
||||||
# dhcp_lease_metrics = BaseCollector.info_collector('dhcp_lease', 'DHCP Active Leases', dhcp_lease_records, dhcp_lease_labels)
|
# dhcp_lease_metrics = BaseCollector.info_collector('dhcp_lease', 'DHCP Active Leases', dhcp_lease_records, dhcp_lease_labels)
|
||||||
# yield dhcp_lease_metrics
|
# yield dhcp_lease_metrics
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class DHCPMetricsDataSource:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def metric_records(router_entry, *, metric_labels = None, add_router_id = True, dhcp_cache = True, translate = True, bound = False):
|
def metric_records(router_entry, *, metric_labels = None, add_router_id = True, dhcp_cache = True, translate = True, bound = False):
|
||||||
if metric_labels is None or dhcp_cache:
|
if metric_labels is None or dhcp_cache:
|
||||||
metric_labels = ['host_name', 'comment', 'active_address', 'address', 'mac_address', 'server', 'expires_after']
|
metric_labels = ['host_name', 'comment', 'active_address', 'address', 'mac_address', 'server', 'expires_after', 'last_seen', 'client_id', 'active_mac_address']
|
||||||
|
|
||||||
if dhcp_cache and router_entry.dhcp_records:
|
if dhcp_cache and router_entry.dhcp_records:
|
||||||
return router_entry.dhcp_records
|
return router_entry.dhcp_records
|
||||||
@@ -51,5 +51,3 @@ class DHCPMetricsDataSource:
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(f'Error getting dhcp info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
|
print(f'Error getting dhcp info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user