Skip to content

Commit

Permalink
coding style optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
akpw committed Jul 27, 2024
1 parent b13b3b6 commit eda24cd
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 64 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ The default configuration file comes with a sample configuration, making it easy
capsman_clients = True # CAPsMAN clients metrics
lte = False # LTE signal and status metrics
ipsec = False # IPSec active peer metrics
kid_control_assigned = False # Allow Kid Control metrics for connected devices with assigned users
kid_control_dynamic = False # Allow Kid Control metrics for all connected devices, including those without assigned user
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ stringData:
capsman_clients = True # CAPsMAN clients metrics
lte = False # LTE signal and status metrics
ipsec = False # IPSec active peer metrics
kid_control_assigned = False # Allow Kid Control metrics for connected devices with assigned users
kid_control_dynamic = False # Allow Kid Control metrics for all connected devices, including those without assigned user
Expand All @@ -116,4 +117,3 @@ stringData:
check_for_updates = False # check for available ROS updates
ipsec = False # IPSec active peer metrics
4 changes: 2 additions & 2 deletions mktxp/cli/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ class ConfigEntry:
MKTXPConfigKeys.FE_DHCP_KEY, MKTXPConfigKeys.FE_PACKAGE_KEY, MKTXPConfigKeys.FE_DHCP_LEASE_KEY, MKTXPConfigKeys.FE_INTERFACE_KEY,
MKTXPConfigKeys.FE_MONITOR_KEY, MKTXPConfigKeys.FE_WIRELESS_KEY, MKTXPConfigKeys.FE_WIRELESS_CLIENTS_KEY,
MKTXPConfigKeys.FE_IP_CONNECTIONS_KEY, MKTXPConfigKeys.FE_CONNECTION_STATS_KEY, MKTXPConfigKeys.FE_CAPSMAN_KEY, MKTXPConfigKeys.FE_CAPSMAN_CLIENTS_KEY, MKTXPConfigKeys.FE_POE_KEY,
MKTXPConfigKeys.FE_NETWATCH_KEY, MKTXPConfigKeys.FE_LTE_KEY, MKTXPConfigKeys.MKTXP_USE_COMMENTS_OVER_NAMES, MKTXPConfigKeys.FE_PUBLIC_IP_KEY,
MKTXPConfigKeys.FE_NETWATCH_KEY, MKTXPConfigKeys.MKTXP_USE_COMMENTS_OVER_NAMES, MKTXPConfigKeys.FE_PUBLIC_IP_KEY,
MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_FIREWALL_KEY, MKTXPConfigKeys.FE_NEIGHBOR_KEY,
MKTXPConfigKeys.FE_IPV6_ROUTE_KEY, MKTXPConfigKeys.FE_IPV6_DHCP_POOL_KEY, MKTXPConfigKeys.FE_IPV6_FIREWALL_KEY, MKTXPConfigKeys.FE_IPV6_NEIGHBOR_KEY,
MKTXPConfigKeys.FE_USER_KEY, MKTXPConfigKeys.FE_QUEUE_KEY, MKTXPConfigKeys.FE_REMOTE_DHCP_ENTRY, MKTXPConfigKeys.FE_REMOTE_CAPSMAN_ENTRY, MKTXPConfigKeys.FE_CHECK_FOR_UPDATES, MKTXPConfigKeys.FE_BGP_KEY,
MKTXPConfigKeys.FE_KID_CONTROL_DEVICE, MKTXPConfigKeys.FE_KID_CONTROL_DYNAMIC, MKTXPConfigKeys.FE_IPSEC_KEY
MKTXPConfigKeys.FE_KID_CONTROL_DEVICE, MKTXPConfigKeys.FE_KID_CONTROL_DYNAMIC, MKTXPConfigKeys.FE_LTE_KEY, MKTXPConfigKeys.FE_IPSEC_KEY
])
MKTXPSystemEntry = namedtuple('MKTXPSystemEntry', [MKTXPConfigKeys.PORT_KEY, MKTXPConfigKeys.LISTEN_KEY, MKTXPConfigKeys.MKTXP_SOCKET_TIMEOUT,
MKTXPConfigKeys.MKTXP_INITIAL_DELAY, MKTXPConfigKeys.MKTXP_MAX_DELAY,
Expand Down
2 changes: 1 addition & 1 deletion mktxp/cli/config/mktxp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
capsman_clients = True # CAPsMAN clients metrics

lte = False # LTE signal and status metrics
ipsec = False # IPSec active peer metrics

kid_control_assigned = False # Allow Kid Control metrics for connected devices with assigned users
kid_control_dynamic = False # Allow Kid Control metrics for all connected devices, including those without assigned user
Expand All @@ -75,4 +76,3 @@

check_for_updates = False # check for available ROS updates

ipsec = False # IPSec active peer metrics
106 changes: 51 additions & 55 deletions mktxp/collector/ipsec_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,54 @@ def collect(router_entry):
ipsec_records = IPSecMetricsDataSource.metric_records(router_entry, metric_labels=ipsec_labels,
translation_table=translation_table)

if not ipsec_records:
return

ipsec_info_labels = ['local_address', 'name', 'remote_address', 'state']

ipsec_state_metric = BaseCollector.info_collector('ipsec_peer_state',
'State of negotiation with the peer.',
ipsec_records, ipsec_info_labels)
yield ipsec_state_metric

ipsec_value_labels = ['local_address', 'name', 'remote_address']

rx_byte_metric = BaseCollector.counter_collector('ipsec_peer_rx_byte',
'The total amount of bytes received from this peer.',
ipsec_records, 'rx_bytes', ipsec_value_labels)
yield rx_byte_metric

tx_byte_metric = BaseCollector.counter_collector('ipsec_peer_tx_byte',
'The total amount of bytes transmitted to this peer.',
ipsec_records, 'tx_bytes', ipsec_value_labels)
yield tx_byte_metric

rx_packet_metric = BaseCollector.counter_collector('ipsec_peer_rx_packet',
'The total amount of packets received from this peer.',
ipsec_records, 'rx_packets', ipsec_value_labels)
yield rx_byte_metric

tx_packet_metric = BaseCollector.counter_collector('ipsec_peer_tx_packet',
'The total amount of packets transmitted to this peer.',
ipsec_records, 'tx_packets', ipsec_value_labels)
yield tx_packet_metric

p2_total_metric = BaseCollector.gauge_collector('ipsec_peer_security_association',
'The total amount of active IPsec security associations.',
ipsec_records, 'p2_total', ipsec_value_labels)
yield p2_total_metric

last_seen_metric = BaseCollector.gauge_collector('ipsec_peer_last_seen',
'Duration since the last message received by this peer.',
ipsec_records, 'last_seen', ipsec_value_labels)
yield last_seen_metric

uptime_metric = BaseCollector.gauge_collector('ipsec_peer_uptime', 'How long peer is in an established state.',
ipsec_records, 'uptime', ipsec_value_labels)
yield uptime_metric

responder_metric = BaseCollector.gauge_collector('ipsec_peer_responder',
'Whether the connection is initiated by a remote peer.',
ipsec_records, 'responder', ipsec_value_labels)
yield responder_metric

natt_metric = BaseCollector.gauge_collector('ipsec_peer_natt_enabled',
'Whether NAT-T is used for this peer.',
ipsec_records, 'natt_peer', ipsec_value_labels)
yield natt_metric
if ipsec_records:
ipsec_info_labels = ['local_address', 'name', 'remote_address', 'state']
ipsec_state_metric = BaseCollector.info_collector('ipsec_peer_state',
'State of negotiation with the peer.',
ipsec_records, ipsec_info_labels)
yield ipsec_state_metric

ipsec_value_labels = ['local_address', 'name', 'remote_address']
rx_byte_metric = BaseCollector.counter_collector('ipsec_peer_rx_byte',
'The total amount of bytes received from this peer.',
ipsec_records, 'rx_bytes', ipsec_value_labels)
yield rx_byte_metric

tx_byte_metric = BaseCollector.counter_collector('ipsec_peer_tx_byte',
'The total amount of bytes transmitted to this peer.',
ipsec_records, 'tx_bytes', ipsec_value_labels)
yield tx_byte_metric

rx_packet_metric = BaseCollector.counter_collector('ipsec_peer_rx_packet',
'The total amount of packets received from this peer.',
ipsec_records, 'rx_packets', ipsec_value_labels)
yield rx_byte_metric

tx_packet_metric = BaseCollector.counter_collector('ipsec_peer_tx_packet',
'The total amount of packets transmitted to this peer.',
ipsec_records, 'tx_packets', ipsec_value_labels)
yield tx_packet_metric

p2_total_metric = BaseCollector.gauge_collector('ipsec_peer_security_association',
'The total amount of active IPsec security associations.',
ipsec_records, 'p2_total', ipsec_value_labels)
yield p2_total_metric

last_seen_metric = BaseCollector.gauge_collector('ipsec_peer_last_seen',
'Duration since the last message received by this peer.',
ipsec_records, 'last_seen', ipsec_value_labels)
yield last_seen_metric

uptime_metric = BaseCollector.gauge_collector('ipsec_peer_uptime', 'How long peer is in an established state.',
ipsec_records, 'uptime', ipsec_value_labels)
yield uptime_metric

responder_metric = BaseCollector.gauge_collector('ipsec_peer_responder',
'Whether the connection is initiated by a remote peer.',
ipsec_records, 'responder', ipsec_value_labels)
yield responder_metric

natt_metric = BaseCollector.gauge_collector('ipsec_peer_natt_enabled',
'Whether NAT-T is used for this peer.',
ipsec_records, 'natt_peer', ipsec_value_labels)
yield natt_metric
12 changes: 7 additions & 5 deletions mktxp/collector/lte_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ def collect(router_entry):
kind = 'lte',
running_only = False)
if monitor_records:
# sanitize records for relevant labels
rsrp_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('rsrp')]
rsrq_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('rsrq')]
sinr_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('sinr')]
rssi_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('rssi')]
yield BaseCollector.gauge_collector('lte_pin_status', 'Pin status', monitor_records, 'pin_status', [])
yield BaseCollector.gauge_collector('lte_registration_status', 'Registration status', monitor_records, 'registration_status', [])
yield BaseCollector.info_collector('lte_current_operator', 'LTE operator', monitor_records, ['current_operator', 'access_technology', 'functionality', 'subscriber_number'])
yield BaseCollector.gauge_collector('lte_session_uptime', 'LTE session uptime', monitor_records, 'session_uptime', [])

# specific labels
rsrp_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('rsrp')]
rsrq_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('rsrq')]
sinr_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('sinr')]
rssi_records = [monitor_record for monitor_record in monitor_records if monitor_record.get('rssi')]

if rsrp_records:
yield BaseCollector.gauge_collector('lte_rsrp', 'LTE Reference Signal Received Qualityrsrp value', rsrp_records, 'rsrp', [])
if rsrq_records:
Expand Down

0 comments on commit eda24cd

Please sign in to comment.