From 7b85a0d38838d034ed360e37d94a88c9431e2189 Mon Sep 17 00:00:00 2001 From: Kilian Krause Date: Sun, 9 Jul 2023 22:23:55 +0200 Subject: [PATCH] fix help comment IPv4->IPv6 --- src/capport/stats.py | 68 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/src/capport/stats.py b/src/capport/stats.py index fb82db7..250aee5 100644 --- a/src/capport/stats.py +++ b/src/capport/stats.py @@ -12,22 +12,28 @@ import capport.utils.nft_set from . import cptypes -def print_metric(name: str, mtype: str, value, *, now: typing.Optional[int] = None, help: typing.Optional[str] = None): +def print_metric( + name: str, + mtype: str, + value, + *, + now: typing.Optional[int] = None, + help: typing.Optional[str] = None, +): # no labels in our names for now, always print help and type if help: - print(f'# HELP {name} {help}') - print(f'# TYPE {name} {mtype}') + print(f"# HELP {name} {help}") + print(f"# TYPE {name} {mtype}") if now: - print(f'{name} {value} {now}') + print(f"{name} {value} {now}") else: - print(f'{name} {value}') + print(f"{name} {value}") async def amain(client_ifname: str): ns = capport.utils.nft_set.NftSet() captive_allowed_entries: typing.Set[cptypes.MacAddress] = { - entry['mac'] - for entry in ns.list() + entry["mac"] for entry in ns.list() } seen_allowed_entries: typing.Set[cptypes.MacAddress] = set() total_ipv4 = 0 @@ -48,49 +54,51 @@ async def amain(client_ifname: str): total_ipv6 += 1 unique_ipv6.add(mac) print_metric( - 'capport_allowed_macs', - 'gauge', + "capport_allowed_macs", + "gauge", len(captive_allowed_entries), - help='Number of allowed client mac addresses', + help="Number of allowed client mac addresses", ) print_metric( - 'capport_allowed_neigh_macs', - 'gauge', + "capport_allowed_neigh_macs", + "gauge", len(seen_allowed_entries), - help='Number of allowed client mac addresses seen in neighbor cache', + help="Number of allowed client mac addresses seen in neighbor cache", ) print_metric( - 'capport_unique', - 'gauge', + "capport_unique", + "gauge", len(unique_clients), - help='Number of clients (mac addresses) in client network seen in neighbor cache', + help="Number of clients (mac addresses) in client network seen in neighbor cache", ) print_metric( - 'capport_unique_ipv4', - 'gauge', + "capport_unique_ipv4", + "gauge", len(unique_ipv4), - help='Number of IPv4 clients (unique per mac) in client network seen in neighbor cache', + help="Number of IPv4 clients (unique per mac) in client network seen in neighbor cache", ) print_metric( - 'capport_unique_ipv6', - 'gauge', + "capport_unique_ipv6", + "gauge", len(unique_ipv6), - help='Number of IPv4 clients (unique per mac) in client network seen in neighbor cache', + help="Number of IPv6 clients (unique per mac) in client network seen in neighbor cache", ) print_metric( - 'capport_total_ipv4', - 'gauge', + "capport_total_ipv4", + "gauge", total_ipv4, - help='Number of IPv4 addresses seen in neighbor cache', + help="Number of IPv4 addresses seen in neighbor cache", ) print_metric( - 'capport_total_ipv6', - 'gauge', + "capport_total_ipv6", + "gauge", total_ipv6, - help='Number of IPv6 addresses seen in neighbor cache', + help="Number of IPv6 addresses seen in neighbor cache", ) def main(): - assert len(sys.argv) == 2, "Need name of client interface as argument" - trio.run(amain, sys.argv[1]) + if len(sys.argv) != 2: + print("Need name of client interface as argument") + sys.exit(1) + trio.run(amain, sys.argv[1:])