-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
179 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# 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.bgp_ds import BGPMetricsDataSource | ||
|
||
|
||
class BGPCollector(BaseCollector): | ||
'''BGP collector''' | ||
@staticmethod | ||
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_records = BGPMetricsDataSource.metric_records(router_entry, metric_labels=bgp_labels) | ||
|
||
|
||
if bgp_records: | ||
# translate records to appropriate values | ||
translated_fields = ['established', 'uptime'] | ||
for bgp_record in bgp_records: | ||
for translated_field in translated_fields: | ||
value = bgp_record.get(translated_field, None) | ||
if value: | ||
bgp_record[translated_field] = BGPCollector._translated_values(translated_field, value) | ||
|
||
session_info_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_info_labes) | ||
yield bgp_sessions_metrics | ||
|
||
session_id_labes = ['name'] | ||
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) | ||
yield local_messages_metrics | ||
|
||
|
||
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) | ||
yield local_bytes_metrics | ||
|
||
|
||
prefix_count_metrics = BaseCollector.gauge_collector('bgp_prefix_count', 'BGP prefix count', bgp_records, 'prefix_count', session_id_labes) | ||
yield prefix_count_metrics | ||
|
||
|
||
established_metrics = BaseCollector.gauge_collector('bgp_established', 'BGP established', bgp_records, 'established', session_id_labes) | ||
yield established_metrics | ||
|
||
|
||
uptime_metrics = BaseCollector.gauge_collector('bgp_uptime', 'BGP uptime in milliseconds', bgp_records, 'uptime', session_id_labes) | ||
yield uptime_metrics | ||
|
||
|
||
# Helpers | ||
@staticmethod | ||
def _translated_values(translated_field, value): | ||
return { | ||
'established': lambda value: '1' if value=='true' else '0', | ||
'uptime': lambda value: BaseOutputProcessor.parse_timedelta_milliseconds(value) | ||
}[translated_field](value) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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.datasource.base_ds import BaseDSProcessor | ||
|
||
|
||
class BGPMetricsDataSource: | ||
''' Wireless Metrics data provider | ||
''' | ||
@staticmethod | ||
def metric_records(router_entry, *, metric_labels = None, add_router_id = True): | ||
if metric_labels is None: | ||
metric_labels = [] | ||
try: | ||
bgp_records = router_entry.api_connection.router_api().get_resource('/routing/bgp/session').get() | ||
return BaseDSProcessor.trimmed_records(router_entry, router_records = bgp_records, metric_labels = metric_labels, add_router_id = add_router_id) | ||
except Exception as exc: | ||
print(f'Error getting BGP sessions info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') | ||
return None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.