-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from lanrat/routing_stats
Add Routing Process Stats collector
- Loading branch information
Showing
9 changed files
with
93 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ k8s | |
build | ||
dist | ||
mktxp.egg-info | ||
tests | ||
tests/ | ||
.github/ | ||
deploy/ |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
FROM python:3-alpine | ||
LABEL org.opencontainers.image.source github.com/akpw/mktxp | ||
Check warning on line 2 in Dockerfile GitHub Actions / Call Docker BuildLegacy key/value format with whitespace separator should not be used
|
||
RUN addgroup -S mktxp && adduser -S mktxp -G mktxp | ||
RUN apk add nano | ||
|
||
WORKDIR /mktxp | ||
COPY . . | ||
RUN pip install ./ && apk add nano | ||
RUN pip install ./ | ||
|
||
EXPOSE 49090 | ||
RUN addgroup -S mktxp && adduser -S mktxp -G mktxp | ||
|
||
USER mktxp | ||
ENTRYPOINT ["/usr/local/bin/mktxp"] | ||
CMD ["export"] |
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,46 @@ | ||
# coding=utf8 | ||
|
||
from mktxp.collector.base_collector import BaseCollector | ||
from mktxp.datasource.routing_stats_ds import RoutingStatsMetricsDataSource | ||
from mktxp.utils.utils import parse_mkt_uptime | ||
|
||
|
||
class RoutingStatsCollector(BaseCollector): | ||
'''Routing Stats collector''' | ||
@staticmethod | ||
def collect(router_entry): | ||
if not router_entry.config_entry.routing_stats: | ||
return | ||
|
||
routing_stats_labels = ['tasks', 'id', 'private_mem_blocks', 'shared_mem_blocks', 'kernel_time', 'process_time', 'max_busy', 'max_calc'] | ||
translation_table = { | ||
'kernel_time': lambda value: parse_mkt_uptime(value), | ||
'process_time': lambda value: parse_mkt_uptime(value), | ||
'max_busy': lambda value: parse_mkt_uptime(value), | ||
'max_calc': lambda value: parse_mkt_uptime(value), | ||
} | ||
routing_stats_records = RoutingStatsMetricsDataSource.metric_records(router_entry, metric_labels=routing_stats_labels, translation_table = translation_table) | ||
|
||
if routing_stats_records: | ||
session_info_labels = ['tasks', 'id', 'pid'] | ||
routing_stats_processes_metrics = BaseCollector.info_collector('routing_stats_processes', 'Routing Process Stats', routing_stats_records, session_info_labels) | ||
yield routing_stats_processes_metrics | ||
|
||
session_id_labels = ['tasks'] | ||
routing_stats_private_mem_metrics = BaseCollector.gauge_collector('routing_stats_private_mem', 'Private Memory Blocks Used', routing_stats_records, 'private_mem_blocks', session_id_labels) | ||
yield routing_stats_private_mem_metrics | ||
|
||
routing_stats_shared_mem_metrics = BaseCollector.gauge_collector('routing_stats_shared_mem', 'Shared Memory Blocks Used', routing_stats_records, 'shared_mem_blocks', session_id_labels) | ||
yield routing_stats_shared_mem_metrics | ||
|
||
kernel_time_metrics = BaseCollector.counter_collector('routing_stats_kernel_time', 'Process Kernel Time', routing_stats_records, 'kernel_time', session_id_labels) | ||
yield kernel_time_metrics | ||
|
||
process_time_metrics = BaseCollector.counter_collector('routing_stats_process_time', 'Process Time', routing_stats_records, 'process_time', session_id_labels) | ||
yield process_time_metrics | ||
|
||
max_busy_metrics = BaseCollector.counter_collector('routing_stats_max_busy', 'Max Busy Time', routing_stats_records, 'max_busy', session_id_labels) | ||
yield max_busy_metrics | ||
|
||
max_calc_metrics = BaseCollector.counter_collector('routing_stats_max_calc', 'Max Calc Time', routing_stats_records, 'max_calc', session_id_labels) | ||
yield max_calc_metrics |
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,27 @@ | ||
|
||
from mktxp.datasource.base_ds import BaseDSProcessor | ||
from mktxp.datasource.system_resource_ds import SystemResourceMetricsDataSource | ||
from mktxp.utils.utils import routerOS7_version | ||
|
||
|
||
class RoutingStatsMetricsDataSource: | ||
''' Routing Stats data provider | ||
''' | ||
@staticmethod | ||
def metric_records(router_entry, *, metric_labels = None, translation_table = None): | ||
if metric_labels is None: | ||
metric_labels = [] | ||
try: | ||
routing_stats = '/routing/stats/process' | ||
|
||
# legacy 6.x versions are untested | ||
ver = SystemResourceMetricsDataSource.os_version(router_entry) | ||
if not routerOS7_version(ver): | ||
return | ||
|
||
routing_stats_records = router_entry.api_connection.router_api().get_resource(routing_stats).get() | ||
return BaseDSProcessor.trimmed_records(router_entry, router_records = routing_stats_records, metric_labels = metric_labels, translation_table = translation_table) | ||
except Exception as exc: | ||
print(f'Error getting routing stats 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