8000 Add support to collect bfd metrics by phibos · Pull Request #227 · akpw/mktxp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support to collect bfd metrics #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mktxp/cli/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CollectorKeys:
QUEUE_SIMPLE_COLLECTOR = 'QueueSimpleCollector'
KID_CONTROL_DEVICE_COLLECTOR = 'KidControlCollector'
USER_COLLECTOR = 'UserCollector'
BFD_COLLECTOR = 'BFDCollector'
BGP_COLLECTOR = 'BGPCollector'
ROUTING_STATS_COLLECTOR = 'RoutingStatsCollector'
EOIP_COLLECTOR = 'EOIPCollector'
Expand Down Expand Up @@ -111,6 +112,7 @@ class MKTXPConfigKeys:

FE_USER_KEY = 'user'
FE_QUEUE_KEY = 'queue'
FE_BFD_KEY = 'bfd'
FE_BGP_KEY = 'bgp'

FE_REMOTE_DHCP_ENTRY = 'remote_dhcp_entry'
Expand Down Expand Up @@ -169,7 +171,7 @@ class MKTXPConfigKeys:


BOOLEAN_KEYS_NO = {ENABLED_KEY, SSL_KEY, NO_SSL_CERTIFICATE, FE_CHECK_FOR_UPDATES, FE_KID_CONTROL_DEVICE, FE_KID_CONTROL_DYNAMIC,
SSL_CERTIFICATE_VERIFY, FE_IPV6_ROUTE_KEY, FE_IPV6_DHCP_POOL_KEY, FE_IPV6_FIREWALL_KEY, FE_IPV6_NEIGHBOR_KEY, FE_CONNECTION_STATS_KEY, FE_BGP_KEY,
SSL_CERTIFICATE_VERIFY, FE_IPV6_ROUTE_KEY, FE_IPV6_DHCP_POOL_KEY, FE_IPV6_FIREWALL_KEY, FE_IPV6_NEIGHBOR_KEY, FE_CONNECTION_STATS_KEY, FE_BFD_KEY, FE_BGP_KEY,
FE_EOIP_KEY, FE_GRE_KEY, FE_IPIP_KEY, FE_IPSEC_KEY, FE_LTE_KEY, FE_SWITCH_PORT_KEY, FE_ROUTING_STATS_KEY, FE_CERTIFICATE_KEY, FE_DNS_KEY}

# Feature keys enabled by default
Expand Down Expand Up @@ -202,7 +204,7 @@ class ConfigEntry:
MKTXPConfigKeys.FE_NETWATCH_KEY, MKTXPConfigKeys.MKTXP_USE_COMMENTS_OVER_NAMES, MKTXPConfigKeys.FE_PUBLIC_IP_KEY,
MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_FIREWALL_KEY, MKTXPConfigKeys.FE_NEIGHBOR_KEY, MKTXPConfigKeys.FE_DNS_KEY,
MKTXPConfigKeys.FE_IPV6_ROUTE_KEY, MKTXPConfigKeys.FE_IPV6_DHCP_POOL_KEY, MKTXPConfigKeys.FE_IPV6_FIREWALL_KEY, MKTXPConfigKeys.FE_IPV6_NEIGHBOR_KEY,
MKTXPConfigKeys.FE_USER_KEY, MKTXPConfigKeys.FE_QUEUE_KEY, MKTXPConfigKeys.FE_REMOTE_DHCP_ENTRY, MKTXPConfigKeys.FE_REMOTE_CAPSMAN_ENTRY, MKTXPConfigKeys.FE_CHECK_FOR_UPDATES, MKTXPConfigKeys.FE_BGP_KEY,
MKTXPConfigKeys.FE_USER_KEY, MKTXPConfigKeys.FE_QUEUE_KEY, MKTXPConfigKeys.FE_REMOTE_DHCP_ENTRY, MKTXPConfigKeys.FE_REMOTE_CAPSMAN_ENTRY, MKTXPConfigKeys.FE_CHECK_FOR_UPDATES, MKTXPConfigKeys.FE_BFD_KEY, MKTXPConfigKeys.FE_BGP_KEY,
MKTXPConfigKeys.FE_KID_CONTROL_DEVICE, MKTXPConfigKeys.FE_KID_CONTROL_DYNAMIC, MKTXPConfigKeys.FE_EOIP_KEY, MKTXPConfigKeys.FE_GRE_KEY, MKTXPConfigKeys.FE_IPIP_KEY, MKTXPConfigKeys.FE_LTE_KEY, MKTXPConfigKeys.FE_IPSEC_KEY, MKTXPConfigKeys.FE_SWITCH_PORT_KEY,
MKTXPConfigKeys.FE_ROUTING_STATS_KEY, MKTXPConfigKeys.FE_CERTIFICATE_KEY
])
Expand Down
1 change: 1 addition & 0 deletions mktxp/cli/config/mktxp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
user = True # Active Users metrics
queue = True # Queues metrics

bfd = False # BFD sessions metrics
bgp = False # BGP sessions metrics
routing_stats = False # Routing process stats
certificate = False # Certificates metrics
Expand Down
108 changes: 108 additions & 0 deletions mktxp/collector/bfd_collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# coding=utf8
## Copyright (c) 2020 Arseniy Kuznetsov
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.


from mktxp.collector.base_collector import BaseCollector
from mktxp.flow.processor.output import BaseOutputProcessor
from mktxp.datasource.bfd_ds import BFDMetricsDataSource


class BFDCollector(BaseCollector):
"""
Bidirectional Forwarding Detection (BFD) collector
"""
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.bfd:
return

translation_table = {
"actual_tx_interval": lambda value: BaseOutputProcessor.parse_timedelta_milliseconds(value, ms_span=True) if value else "0",
"desired_tx_interval": lambda value: BaseOutputProcessor.parse_timedelta_milliseconds(value, ms_span=True) if value else "0",
"hold_time": lambda value: BaseOutputProcessor.parse_timedelta_milliseconds(value, ms_span=True) if value else "0",
"up": lambda value: "1" if value == "true" else "0",
"uptime": lambda value: BaseOutputProcessor.parse_timedelta_milliseconds(value) if value else "0",
}

default_labels = ["local_address", "remote_address"]
metric_records = BFDMetricsDataSource.metric_records(
router_entry,
translation_table=translation_table,
)

if not metric_records:
return

yield BaseCollector.gauge_collector(
"bfd_multiplier",
"The multiplier",
metric_records,
metric_key="multiplier",
metric_labels=default_labels
)
yield BaseCollector.gauge_collector(
"bfd_hold_time",
"The hold time in milliseconds",
metric_records,
metric_key="hold_time",
metric_labels=default_labels
)
yield BaseCollector.counter_collector(
"bfd_rx_packet",
"BFD control packets received",
metric_records,
metric_key="packets_rx",
metric_labels=default_labels,
)
yield BaseCollector.counter_collector(
"bfd_state_change",
"Number of time the state changed",
metric_records,
metric_key="state_changes",
metric_labels=default_labels,
)
yield BaseCollector.gauge_collector(
"bfd_tx_interval",
"The actual transmit interval",
metric_records,
metric_key="actual_tx_interval",
metric_labels=default_labels
)
yield BaseCollector.gauge_collector(
"bfd_tx_interval_desired",
"Desired transmit interval is the highes value from local tx interval and remote minimum rx interval",
metric_records,
metric_key="desired_tx_interval",
metric_labels=default_labels
)
yield BaseCollector.counter_collector(
"bfd_tx_packet",
"BFD control packets transmitted",
metric_records,
metric_key="packets_tx",
metric_labels=default_labels,
)
yield BaseCollector.gauge_collector(
"bfd_up",
"BFD is up",
metric_records,
metric_key="up",
metric_labels=default_labels
)
yield BaseCollector.gauge_collector(
"bfd_uptime",
"BFD uptime in milliseconds",
metric_records,
metric_key="uptime",
metric_labels=default_labels
)
35 changes: 35 additions & 0 deletions mktxp/datasource/bfd_ds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# coding=utf8
## Copyright (c) 2020 Arseniy Kuznetsov
##
## This program is free so 8000 ftware; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.


from mktxp.datasource.base_ds import BaseDSProcessor
from mktxp.datasource.system_resource_ds import SystemResourceMetricsDataSource


class BFDMetricsDataSource:
"""Bidirectional Forwarding Detection (BFD) data provider"""
@staticmethod
def metric_records(router_entry, *, metric_labels = None, translation_table = None):
if metric_labels is None:
metric_labels = []
try:
bfd_records = router_entry.api_connection.router_api().get_resource("/routing/bfd/session").get()
return BaseDSProcessor.trimmed_records(
router_entry,
router_records=bfd_records,
metric_labels=metric_labels,
translation_table=translation_table
)
except Exception as exc:
print(f"Error getting BFD sessions info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}")
return None
2 changes: 2 additions & 0 deletions mktxp/flow/collector_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from mktxp.collector.queue_collector import QueueTreeCollector
from mktxp.collector.queue_collector import QueueSimpleCollector
from mktxp.collector.kid_control_device_collector import KidDeviceCollector
from mktxp.collector.bfd_collector import BFDCollector
from mktxp.collector.bgp_collector import BGPCollector
from mktxp.collector.routing_stats_collector import RoutingStatsCollector
from mktxp.collector.eoip_collector import EOIPCollector
Expand Down Expand Up @@ -86,6 +87,7 @@ def __init__(self):
self.register(CollectorKeys.QUEUE_SIMPLE_COLLECTOR, QueueSimpleCollector.collect)

self.register(CollectorKeys.KID_CONTROL_DEVICE_COLLECTOR, KidDeviceCollector.collect)
self.register(CollectorKeys.BFD_COLLECTOR, BFDCollector.collect)
self.register(CollectorKeys.BGP_COLLECTOR, BGPCollector.collect)
self.register(CollectorKeys.EOIP_COLLECTOR, EOIPCollector.collect)
self.register(CollectorKeys.GRE_COLLECTOR, GRECollector.collect)
Expand Down
1 change: 1 addition & 0 deletions mktxp/flow/router_entry.py
Original 65CC file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, router_name):
CollectorKeys.QUEUE_SIMPLE_COLLECTOR: 0,
CollectorKeys.KID_CONTROL_DEVICE_COLLECTOR: 0,
CollectorKeys.USER_COLLECTOR: 0,
CollectorKeys.BFD_COLLECTOR: 0,
CollectorKeys.BGP_COLLECTOR: 0,
CollectorKeys.ROUTING_STATS_COLLECTOR: 0,
CollectorKeys.EOIP_COLLECTOR: 0,
Expand Down
Loading
0