POE collector, bandwidth metrics on/off switch, fixes/optimizations

This commit is contained in:
Arseniy Kuznetsov
2021-04-01 11:10:29 +02:00
parent 8de1ae1253
commit c7f3377c10
10 changed files with 124 additions and 29 deletions

View File

@@ -33,6 +33,9 @@ class BandwidthCollector(BaseCollector):
self.last_call_timestamp = 0
def collect(self):
if not config_handler.system_entry().bandwidth:
return
if result_list:
result_dict = result_list[0]
bandwidth_records = [{'direction': key, 'bandwidth': str(result_dict[key])} for key in ('download', 'upload')]

View File

@@ -25,7 +25,7 @@ class MonitorCollector(BaseCollector):
if not router_entry.config_entry.monitor:
return
monitor_labels = ('status', 'rate', 'full_duplex', 'name')
monitor_labels = ['status', 'rate', 'full_duplex', 'name']
monitor_records = InterfaceMonitorMetricsDataSource.metric_records(router_entry, metric_labels = monitor_labels, include_comments = True)
if monitor_records:
# translate records to appropriate values

View File

@@ -0,0 +1,34 @@
# 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.poe_ds import POEMetricsDataSource
class POECollector(BaseCollector):
''' POE Metrics collector
'''
@staticmethod
def collect(router_entry):
if not router_entry.config_entry.poe:
return
poe_labels = ['name', 'poe_out', 'poe_priority', 'poe_voltage', 'poe_out_status', 'poe_out_voltage', 'poe_out_current', 'poe_out_power']
poe_records = POEMetricsDataSource.metric_records(router_entry, include_comments = True, metric_labels = poe_labels)
if poe_records:
poe_metrics = BaseCollector.info_collector('poe', 'POE Metrics', poe_records, poe_labels)
yield poe_metrics