Hi!
I’ve set up a Tor Node yesterday and i wanted to monitor it’s traffic (not just the total bandwidth, I already accomplished this with a python script and the Control Port).
I know that nyx exists and it can show realtime network traffic as well as total traffic.
However, i am unable to find out where i can get the realtime metrics for the traffic from the Control Port and thus importing it into Grafana with Prometheus.
How can i achieve that? Where do i have to look to find realtime traffic data? Where does nyx get that data from?
I have found some Grafana dashboards using Influxdb, but i’d like to get it running with Prometheus.
Reading the Control Port documentation I found bw-event-cache
, but this doesn’t seem to generate new data unless Nyx is opened and running.
Sample python code to get bw-event-cache
output:
from stem import Signal
from stem.control import Controller
def get_bandwidth_data():
with Controller.from_port(port=9051) as controller:
controller.authenticate("xxxxx")
# Request bandwidth information using get_info
bw_info = controller.get_info("bw-event-cache")
# Parse the bandwidth information
bw_data = {}
for entry in bw_info.split():
parts = entry.split(',')
if len(parts) == 2:
read, write = map(int, parts)
bw_data['Read'] = read
bw_data['Write'] = write
print(bw_data)
if __name__ == "__main__":
get_bandwidth_data()