Skip to content

Commit

Permalink
BGP session metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
akpw committed Mar 3, 2024
1 parent 5b513ee commit f70719d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 6 additions & 6 deletions mktxp/collector/bgp_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def collect(router_entry):
if not router_entry.config_entry.bgp:
return

bgp_labels = ['name', 'remote.address', 'remote.as', 'local.as', 'remote.afi', 'local.afi', 'remote.messages', 'remote.bytes', 'local.messages', 'local.bytes', 'prefix_count', 'established', 'uptime']
bgp_labels = ['name', 'remote_address', 'remote_as', 'local_as', 'remote_afi', 'local_afi', 'remote_messages', 'remote_bytes', 'local_messages', 'local_bytes', 'prefix_count', 'established', 'uptime']
bgp_records = BGPMetricsDataSource.metric_records(router_entry, metric_labels=bgp_labels)


Expand All @@ -37,23 +37,23 @@ def collect(router_entry):
if value:
bgp_record[translated_field] = BGPCollector._translated_values(translated_field, value)

session_id_labes = ['name', 'remote.address', 'remote.as', 'local.as', 'remote.afi', 'local.afi']
session_id_labes = ['name', 'remote_address', 'remote_as', 'local_as', 'remote_afi', 'local_afi']
bgp_sessions_metrics = BaseCollector.info_collector('bgp_sessions_info', 'BGP sessions info', bgp_records, session_id_labes)
yield bgp_sessions_metrics

remote_messages_metrics = BaseCollector.counter_collector('bgp_remote_messages', 'Number of remote messages', bgp_records, 'remote.messages', session_id_labes)
remote_messages_metrics = BaseCollector.counter_collector('bgp_remote_messages', 'Number of remote messages', bgp_records, 'remote_messages', session_id_labes)
yield remote_messages_metrics


local_messages_metrics = BaseCollector.counter_collector('bgp_local_messages', 'Number of local messages', bgp_records, 'local.messages', session_id_labes)
local_messages_metrics = BaseCollector.counter_collector('bgp_local_messages', 'Number of local messages', bgp_records, 'local_messages', session_id_labes)
yield local_messages_metrics


remote_bytes_metrics = BaseCollector.counter_collector('bgp_remote_bytes', 'Number of remote bytes', bgp_records, 'remote.bytes', session_id_labes)
remote_bytes_metrics = BaseCollector.counter_collector('bgp_remote_bytes', 'Number of remote bytes', bgp_records, 'remote_bytes', session_id_labes)
yield remote_bytes_metrics


local_bytes_metrics = BaseCollector.counter_collector('bgp_local_bytes', 'Number of local bytes', bgp_records, 'local.bytes', session_id_labes)
local_bytes_metrics = BaseCollector.counter_collector('bgp_local_bytes', 'Number of local bytes', bgp_records, 'local_bytes', session_id_labes)
yield local_bytes_metrics


Expand Down
17 changes: 13 additions & 4 deletions mktxp/datasource/base_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ def trimmed_records(router_entry, *, router_records = None, metric_labels = None
if metric_labels is None:
metric_labels = []
if translation_table is None:
translation_table = {}
dash2_ = lambda x : x.replace('-', '_')
translation_table = {}
if len(metric_labels) == 0 and len(router_records) > 0:
metric_labels = [dash2_(key) for key in router_records[0].keys()]
metric_labels = [BaseDSProcessor._normalise_keys(key) for key in router_records[0].keys()]
metric_labels = set(metric_labels)

labeled_records = []
for router_record in router_records:
translated_record = {dash2_(key): value for (key, value) in router_record.items() if dash2_(key) in metric_labels}
translated_record = {BaseDSProcessor._normalise_keys(key): value for (key, value) in router_record.items() if BaseDSProcessor._normalise_keys(key) in metric_labels}

if add_router_id:
for key, value in router_entry.router_id.items():
Expand All @@ -43,3 +42,13 @@ def trimmed_records(router_entry, *, router_records = None, metric_labels = None
labeled_records.append(translated_record)

return labeled_records


@staticmethod
def _normalise_keys(key):
chars = ".-"
for chr in chars:
if chr in key:
key = key.replace(chr, "_")
return key

0 comments on commit f70719d

Please sign in to comment.