Github Mirror / telegraf-plugins: 8b600351




Provide breakdown of counters between accept and reject (utilities/telegraf-plugins#4)

Provide breakdown of counters between accept and reject (utilities/telegraf-plugins#4)

Commit 8b600351.

Authored 2022-05-14T13:27:56.000+01:00 by B Tasker in project Github Mirror / telegraf-plugins

+65 lines -3 lines

Commit Signature

Changes

diff --git a/tor-daemon/README.md b/tor-daemon/README.md
--- a/tor-daemon/README.md
+++ b/tor-daemon/README.md
# @@ -104,7 +104,20 @@ For relays/exit nodes:
# - `ipv4_exit_policy_num_unique_hosts`: Number of unique hosts in exit policies
# - `ipv4_exit_policy_num_unique_ports`: Number of unique ports in exit policies
# - `ipv4_exit_policy_num_wildcard_port`: Number of policies with wildcarded ports
# -- `ipv4_exit_policy_num_specific_port`: Number of policies mentioning specific port
# +- `ipv4_exit_policy_num_specific_port`: Number of policies mentioning specific ports
# +- `ipv4_exit_policy_num_port_range`: Number of policies specifying a range of ports
# +- `ipv4_wildcard_accept` : How many accept policies use wildcards
# +- `ipv4_specific_accept` : How many accept policies specify specific hosts/networks
# +- `ipv4_wildcard_port_accept` : How many accept policies use wildcard for ports
# +- `ipv4_specific_port_accept`: How many accept policies specify specific ports
# +- `ipv4_unique_hosts_accept` : Number of unique hosts in accept policies
# +- `ipv4_unique_ports_accept` : Number of unique hosts in accept policies
# +- `ipv4_wildcard_reject` : How many reject policies use wildcards
# +- `ipv4_specific_reject` : How many reject policies specify specific hosts/networks
# +- `ipv4_wildcard_port_reject` : How many reject policies use wildcard for ports
# +- `ipv4_specific_port_reject`: How many reject policies specify specific ports
# +- `ipv4_unique_hosts_reject` : Number of unique hosts in reject policies
# +- `ipv4_unique_ports_reject` : Number of unique hosts in reject policies
# - `ipv6_exit_policy_num_total`: Total number of exit policies
# - `ipv6_exit_policy_num_accept`: Total number of accept exit policies
# - `ipv6_exit_policy_num_reject`: Total number of reject exit policies
# @@ -114,6 +127,19 @@ For relays/exit nodes:
# - `ipv6_exit_policy_num_unique_ports`: Number of unique ports in exit policies
# - `ipv6_exit_policy_num_wildcard_port`: Number of policies with wildcarded ports
# - `ipv6_exit_policy_num_specific_port`: Number of policies mentioning specific port
# +- `ipv6_exit_policy_num_port_range`: Number of policies specifying a range of ports
# +- `ipv6_wildcard_accept` : How many accept policies use wildcards
# +- `ipv6_specific_accept` : How many accept policies specify specific hosts/networks
# +- `ipv6_wildcard_port_accept` : How many accept policies use wildcard for ports
# +- `ipv6_specific_port_accept`: How many accept policies specify specific ports
# +- `ipv6_unique_hosts_accept` : Number of unique hosts in accept policies
# +- `ipv6_unique_ports_accept` : Number of unique hosts in accept policies
# +- `ipv6_wildcard_reject` : How many reject policies use wildcards
# +- `ipv6_specific_reject` : How many reject policies specify specific hosts/networks
# +- `ipv6_wildcard_port_reject` : How many reject policies use wildcard for ports
# +- `ipv6_specific_port_reject`: How many reject policies specify specific ports
# +- `ipv6_unique_hosts_reject` : Number of unique hosts in reject policies
# +- `ipv6_unique_ports_reject` : Number of unique hosts in reject policies
#
#
# ----
#
diff --git a/tor-daemon/tor-daemon.py b/tor-daemon/tor-daemon.py
--- a/tor-daemon/tor-daemon.py
+++ b/tor-daemon/tor-daemon.py
# @@ -186,11 +186,29 @@ def process_exit_policy(policy_lines):
# "wildcard_port" : 0,
# "specific_port" : 0,
# "port_range": 0,
# +
# +
# + # Policy specific counters
# + "wildcard_accept" : 0,
# + "specific_accept" : 0,
# + "wildcard_port_accept" : 0,
# + "specific_port_accept" : 0,
# +
# +
# + "wildcard_reject" : 0,
# + "specific_reject" : 0,
# + "wildcard_port_reject" : 0,
# + "specific_port_reject" : 0,
# +
# }
#
# hosts = []
# ports = []
# -
# +
# + counts = {
# + "accept" : {"hosts" : [], "ports" : []},
# + "reject" : {"hosts" : [], "ports" : []}
# + }
#
# for policy_line in lines:
# if len(policy_line) == 0:
# @@ -204,39 +222,57 @@ def process_exit_policy(policy_lines):
# parts = policy.split(" ")
# if parts[0].startswith("accept"):
# counters["accept"] += 1
# + mode = "accept"
# else:
# counters["reject"] += 1
# + mode = "reject"
#
# if parts[1].startswith("*"):
# counters["wildcard"] += 1
# + counters["wildcard_" + mode] += 1
# elif parts[1].startswith("1") or parts[1].startswith("2"):
# counters["specific"] += 1
# + counters["specific_" + mode] += 1
#
# # ipv6 complicates this a touch
# ip = ":".join(parts[1].split(":")[0:-1])
# hosts.append(ip)
# + counts[mode]["hosts"].append(ip)
#
# port = parts[1].split(":")[-1]
#
# if "-" in port:
# - # It's a range
# + # It's a range, iterate over it
# counters["port_range"] += 1
# port_parts = [ int(x) for x in port.split("-") ]
# while port_parts[0] <= port_parts[1]:
# ports.append(port_parts[0])
# + counts[mode]["ports"].append(port_parts[0])
# counters['specific_port'] += 1
# + counters["specific_port_" + mode] += 1
# port_parts[0] += 1
#
# else:
# + # Singluar port (or wildcard)
# ports.append(port)
# + counts[mode]["ports"].append(port)
# if port == "*":
# counters['wildcard_port'] += 1
# + counters["wildcard_port_" + mode] += 1
# else:
# counters['specific_port'] += 1
# + counters["specific_port_" + mode] += 1
#
# # Calculate the unique counts
# counters["unique_hosts"] = len(set(hosts))
# counters["unique_ports"] = len(set(ports))
# +
# + counters["unique_hosts_accept"] = len(set(counts["accept"]["hosts"]))
# + counters["unique_ports_accept"] = len(set(counts["accept"]["ports"]))
# + counters["unique_hosts_reject"] = len(set(counts["accept"]["hosts"]))
# + counters["unique_ports_reject"] = len(set(counts["accept"]["ports"]))
# +
# +
#
# return counters
#
#