Queue tree / Active Users collectors, fixes

This commit is contained in:
Arseniy Kuznetsov
2022-12-10 17:47:17 +01:00
parent f5c43a9dd0
commit a93ec2939d
14 changed files with 245 additions and 14 deletions

View File

@@ -41,15 +41,14 @@ class POEMetricsDataSource:
poe_record['poe_out_power'] = poe_monitor_records[0]['poe_out_power']
if include_comments:
interfaces = router_entry.api_connection.router_api().get_resource('/interface/ethernet').get()
comment = lambda interface: interface['comment'] if interface.get('comment') else ''
interfaces = router_entry.api_connection.router_api().get_resource('/interface/ethernet').call('print', {'proplist':'name,comment'})
comment_fn = lambda interface: interface['comment'] if interface.get('comment') else ''
for poe_record in poe_records:
comment = [comment(interface) for interface in interfaces if interface['name'] == poe_record['name']][0]
comment = [comment_fn(interface) for interface in interfaces if interface['name'] == poe_record['name']][0]
if comment:
# combines name with comment
poe_record['name'] = comment if router_entry.config_entry.use_comments_over_names else \
f"{poe_record['name']} ({comment})"
return BaseDSProcessor.trimmed_records(router_entry, router_records = poe_records, metric_labels = metric_labels)
except Exception as exc:
print(f'Error getting PoE info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')

View File

@@ -0,0 +1,45 @@
# 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 QueueTreeMetricsDataSource:
''' Queue Tree Metrics data provider
'''
@staticmethod
def metric_records(router_entry, *, metric_labels = None):
if metric_labels is None:
metric_labels = []
try:
queue_tree_records = router_entry.api_connection.router_api().get_resource('/queue/tree/').get()
return BaseDSProcessor.trimmed_records(router_entry, router_records = queue_tree_records, metric_labels = metric_labels)
except Exception as exc:
print(f'Error getting system resource info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
return None
class SimpleQueueMetricsDataSource:
''' Simple Queue Metrics data provider
'''
@staticmethod
def metric_records(router_entry, *, metric_labels = None):
if metric_labels is None:
metric_labels = []
try:
simple_queue_records = router_entry.api_connection.router_api().get_resource('/queue/simple/').get()
return BaseDSProcessor.trimmed_records(router_entry, router_records = simple_queue_records, metric_labels = metric_labels)
except Exception as exc:
print(f'Error getting system resource info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
return None

View File

@@ -0,0 +1,30 @@
# 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 UserMetricsDataSource:
''' Active Users Metrics data provider
'''
@staticmethod
def metric_records(router_entry, *, metric_labels = None):
if metric_labels is None:
metric_labels = []
try:
active_users_records = router_entry.api_connection.router_api().get_resource('/user/active/').get()
return BaseDSProcessor.trimmed_records(router_entry, router_records = active_users_records, metric_labels = metric_labels)
except Exception as exc:
print(f'Error getting system resource info from router{router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}')
return None