mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 09:40:23 +00:00
expires_after cardinality, bug fixes
This commit is contained in:
@@ -21,3 +21,5 @@
|
||||
|
||||
bandwidth = True # Turns metrics bandwidth metrics collection on / off
|
||||
bandwidth_test_interval = 420 # Interval for colllecting bandwidth metrics
|
||||
|
||||
verbose_mode = False # Set it on for troubleshooting
|
||||
|
||||
@@ -58,6 +58,7 @@ class MKTXPConfigKeys:
|
||||
MKTXP_INC_DIV = 'delay_inc_div'
|
||||
MKTXP_BANDWIDTH_KEY = 'bandwidth'
|
||||
MKTXP_BANDWIDTH_TEST_INTERVAL = 'bandwidth_test_interval'
|
||||
MKTXP_VERBOSE_MODE = 'verbose_mode'
|
||||
|
||||
# UnRegistered entries placeholder
|
||||
NO_ENTRIES_REGISTERED = 'NoEntriesRegistered'
|
||||
@@ -86,7 +87,8 @@ class MKTXPConfigKeys:
|
||||
FE_MONITOR_KEY, FE_ROUTE_KEY, MKTXP_USE_COMMENTS_OVER_NAMES,
|
||||
FE_WIRELESS_KEY, FE_WIRELESS_CLIENTS_KEY, FE_CAPSMAN_KEY, FE_CAPSMAN_CLIENTS_KEY, FE_POE_KEY, FE_NETWATCH_KEY}
|
||||
|
||||
SYSTEM_BOOLEAN_KEYS_YES = (MKTXP_BANDWIDTH_KEY,)
|
||||
SYSTEM_BOOLEAN_KEYS_YES = {MKTXP_BANDWIDTH_KEY}
|
||||
SYSTEM_BOOLEAN_KEYS_NO = {MKTXP_VERBOSE_MODE}
|
||||
|
||||
STR_KEYS = (HOST_KEY, USER_KEY, PASSWD_KEY)
|
||||
MKTXP_INT_KEYS = (PORT_KEY, MKTXP_SOCKET_TIMEOUT, MKTXP_INITIAL_DELAY, MKTXP_MAX_DELAY, MKTXP_INC_DIV, MKTXP_BANDWIDTH_TEST_INTERVAL)
|
||||
@@ -106,14 +108,15 @@ class ConfigEntry:
|
||||
])
|
||||
MKTXPSystemEntry = namedtuple('MKTXPSystemEntry', [MKTXPConfigKeys.PORT_KEY, MKTXPConfigKeys.MKTXP_SOCKET_TIMEOUT,
|
||||
MKTXPConfigKeys.MKTXP_INITIAL_DELAY, MKTXPConfigKeys.MKTXP_MAX_DELAY,
|
||||
MKTXPConfigKeys.MKTXP_INC_DIV, MKTXPConfigKeys.MKTXP_BANDWIDTH_KEY, MKTXPConfigKeys.MKTXP_BANDWIDTH_TEST_INTERVAL])
|
||||
MKTXPConfigKeys.MKTXP_INC_DIV, MKTXPConfigKeys.MKTXP_BANDWIDTH_KEY,
|
||||
MKTXPConfigKeys.MKTXP_VERBOSE_MODE, MKTXPConfigKeys.MKTXP_BANDWIDTH_TEST_INTERVAL])
|
||||
|
||||
|
||||
class OSConfig(metaclass = ABCMeta):
|
||||
''' OS-related config
|
||||
'''
|
||||
@staticmethod
|
||||
def os_config(quiet = False):
|
||||
def os_config():
|
||||
''' Factory method
|
||||
'''
|
||||
if sys.platform == 'linux':
|
||||
@@ -121,8 +124,7 @@ class OSConfig(metaclass = ABCMeta):
|
||||
elif sys.platform == 'darwin':
|
||||
return OSXConfig()
|
||||
else:
|
||||
if not quiet:
|
||||
print(f'Non-supported platform: {sys.platform}')
|
||||
print(f'Non-supported platform: {sys.platform}')
|
||||
return None
|
||||
|
||||
@property
|
||||
@@ -244,11 +246,11 @@ class MKTXPConfigHandler:
|
||||
system_entry_reader[key] = self._default_value_for_key(key)
|
||||
write_needed = True # read from disk next time
|
||||
|
||||
for key in MKTXPConfigKeys.SYSTEM_BOOLEAN_KEYS_YES:
|
||||
for key in MKTXPConfigKeys.SYSTEM_BOOLEAN_KEYS_NO.union(MKTXPConfigKeys.SYSTEM_BOOLEAN_KEYS_YES):
|
||||
if self._config[entry_name].get(key):
|
||||
system_entry_reader[key] = self._config[entry_name].as_bool(key)
|
||||
else:
|
||||
system_entry_reader[key] = True
|
||||
system_entry_reader[key] = True if key in MKTXPConfigKeys.SYSTEM_BOOLEAN_KEYS_YES else False
|
||||
write_needed = True # read from disk next time
|
||||
|
||||
if write_needed:
|
||||
|
||||
@@ -89,18 +89,17 @@ class MKTXPDispatcher:
|
||||
ExportProcessor.start()
|
||||
|
||||
def print(self, args):
|
||||
if not (args['wifi_clients'] or args['capsman_clients']):
|
||||
print("Select metric option(s) to print out, or run 'mktxp print -h' to find out more")
|
||||
|
||||
if args['wifi_clients']:
|
||||
OutputProcessor.wifi_clients(args['entry_name'])
|
||||
|
||||
if args['capsman_clients']:
|
||||
elif args['capsman_clients']:
|
||||
OutputProcessor.capsman_clients(args['entry_name'])
|
||||
|
||||
if args['dhcp_clients']:
|
||||
elif args['dhcp_clients']:
|
||||
OutputProcessor.dhcp_clients(args['entry_name'])
|
||||
|
||||
|
||||
else:
|
||||
print("Select metric option(s) to print out, or run 'mktxp print -h' to find out more")
|
||||
|
||||
def main():
|
||||
MKTXPDispatcher().dispatch()
|
||||
|
||||
@@ -218,8 +218,9 @@ Selected metrics info can be printed on the command line. For more information,
|
||||
return editor
|
||||
|
||||
commands = ['which nano', 'which vi', 'which vim']
|
||||
quiet = not config_handler.system_entry().verbose_mode
|
||||
for command in commands:
|
||||
editor = run_cmd(command, quiet = True).rstrip()
|
||||
editor = run_cmd(command, quiet = quiet).rstrip()
|
||||
if editor:
|
||||
break
|
||||
return editor
|
||||
|
||||
@@ -40,11 +40,20 @@ class DHCPCollector(BaseCollector):
|
||||
'server': key, 'count': value} for key, value in dhcp_lease_servers.items()]
|
||||
|
||||
# yield lease-per-server metrics
|
||||
dhcp_lease_server_metrics = BaseCollector.gauge_collector('dhcp_lease_active_count', 'Number of active leases per DHCP server', dhcp_lease_servers_records, 'count', ['server'])
|
||||
dhcp_lease_server_metrics = BaseCollector.gauge_collector('dhcp_lease_active_count',
|
||||
'Number of active leases per DHCP server',
|
||||
dhcp_lease_servers_records, 'count', ['server'])
|
||||
yield dhcp_lease_server_metrics
|
||||
|
||||
# active lease metrics
|
||||
dhcp_lease_labels.remove('expires_after')
|
||||
if router_entry.config_entry.dhcp_lease:
|
||||
dhcp_lease_metrics = BaseCollector.info_collector('dhcp_lease', 'DHCP Active Leases', dhcp_lease_records, dhcp_lease_labels)
|
||||
yield dhcp_lease_metrics
|
||||
|
||||
dhcp_lease_metrics_gauge = BaseCollector.gauge_collector('dhcp_lease', 'DHCP Active Leases',
|
||||
dhcp_lease_records, 'expires_after', dhcp_lease_labels)
|
||||
yield dhcp_lease_metrics_gauge
|
||||
|
||||
# active lease metrics
|
||||
#if router_entry.config_entry.dhcp_lease:
|
||||
# dhcp_lease_metrics = BaseCollector.info_collector('dhcp_lease', 'DHCP Active Leases', dhcp_lease_records, dhcp_lease_labels)
|
||||
# yield dhcp_lease_metrics
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
|
||||
from mktxp.datasource.base_ds import BaseDSProcessor
|
||||
from mktxp.utils.utils import parse_mkt_uptime
|
||||
|
||||
|
||||
class DHCPMetricsDataSource:
|
||||
@@ -31,7 +32,7 @@ class DHCPMetricsDataSource:
|
||||
if 'host_name' in metric_labels:
|
||||
translation_table['host_name'] = lambda c: c if c else ''
|
||||
if 'expires_after' in metric_labels:
|
||||
translation_table['expires_after'] = lambda c: c if c else ''
|
||||
translation_table['expires_after'] = lambda c: parse_mkt_uptime(c)
|
||||
if 'active_address' in metric_labels:
|
||||
translation_table['active_address'] = lambda c: c if c else ''
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class BaseOutputProcessor:
|
||||
wifi_rates_rgx = re.compile(r'(\d*(?:\.\d*)?)([GgMmKk]bps?)')
|
||||
config_handler.re_compiled['wifi_rates_rgx'] = wifi_rates_rgx
|
||||
rc = wifi_rates_rgx.search(rate)
|
||||
return f'{int(float(rc[1]))} {rc[2]}' if rc else ''
|
||||
return f'{int(float(rc[1]))} {rc[2]}' if rc and len(rc.groups()) == 2 else rate
|
||||
|
||||
@staticmethod
|
||||
def parse_timedelta(time):
|
||||
|
||||
@@ -76,14 +76,14 @@ class RouterAPIConnection:
|
||||
self.connect()
|
||||
return self.api
|
||||
|
||||
def _in_connect_timeout(self, connect_timestamp, quiet = True):
|
||||
def _in_connect_timeout(self, connect_timestamp):
|
||||
connect_delay = self._connect_delay()
|
||||
if (connect_timestamp - self.last_failure_timestamp) < connect_delay:
|
||||
if not quiet:
|
||||
print(f'{self.router_name}@{self.config_entry.hostname}: in connect timeout, {int(connect_delay - (connect_timestamp - self.last_failure_timestamp))}secs remaining')
|
||||
if config_handler.system_entry().verbose_mode:
|
||||
print(f'{self.router_name}@{self.E.hostname}: in connect timeout, {int(connect_delay - (connect_timestamp - self.last_failure_timestamp))}secs remaining')
|
||||
print(f'Successive failure count: {self.successive_failure_count}')
|
||||
return True
|
||||
if not quiet:
|
||||
if config_handler.system_entry().verbose_mode:
|
||||
print(f'{self.router_name}@{self.config_entry.hostname}: OK to connect')
|
||||
if self.last_failure_timestamp > 0:
|
||||
print(f'Seconds since last failure: {connect_timestamp - self.last_failure_timestamp}')
|
||||
|
||||
@@ -18,6 +18,7 @@ from timeit import default_timer
|
||||
from collections.abc import Iterable
|
||||
from contextlib import contextmanager
|
||||
from multiprocessing import Process, Event
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
''' Utilities / Helpers
|
||||
@@ -69,6 +70,11 @@ def get_last_digit(str_to_search):
|
||||
else:
|
||||
return -1
|
||||
|
||||
def parse_mkt_uptime(time):
|
||||
time_dict = re.match(r'((?P<weeks>\d+)w)?((?P<days>\d+)d)?((?P<hours>\d+)h)?((?P<minutes>\d+)m)?((?P<seconds>\d+)s)?', time).groupdict()
|
||||
delta = timedelta(**{key: int(value) for key, value in time_dict.items() if value}).total_seconds()
|
||||
return int(delta) if delta else 0
|
||||
|
||||
class FSHelper:
|
||||
''' File System ops helper
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user