MindFlavor / prometheus_wireguard_exporter

A Prometheus exporter for WireGuard, written in Rust.
https://mindflavor.github.io/prometheus_wireguard_exporter
MIT License
462 stars 49 forks source link

Always reset counter metrics when automation restart wireguard interface #85

Open rahmadsandy opened 2 years ago

rahmadsandy commented 2 years ago

Hello @MindFlavor , honesty this amazing project

could this exporter save all metrics from the beginning with ignoring how often we restarted wireguard interface? or could be store stats into file or some databases

i used this wireguard framework to manage https://github.com/vx3r/wg-gen-web everytime do CUD (Create, Update and Delete) automatically restart wireguard interface image

i think its could be good if this exporter could save from beginning depends from exporter systemd file status image

image

MindFlavor commented 2 years ago

Hello @rahmadsandy, please correct me if I misunderstood. You are suggesting to persist the output of wg show all dump to use in case wireguard is restarting?

rahmadsandy commented 2 years ago

sorry replying lately, yes correct @MindFlavor

but i have tried after restarting wireguard service wg show all dump also resetting all data

MindFlavor commented 2 years ago

We can cache the last wg show all dump output but I am not sure it would help: the counters will get reset anyway at the next poll. I'll try and think about an alternative. If anyone in the community can chip in, it would be most welcome!

rahmadsandy commented 2 years ago

thank you @MindFlavor still waiting your progress 🚀

Lukeid commented 1 month ago

I'm in the same scenario. I would like to keep stats.

Maybe you can store last stats and:

For wireguard_sent_bytes_total: If new_wireguard_sent_bytes_total < last_wireguard_sent_bytes_total then wireguard_sent_bytes_total = new_wireguard_sent_bytes_total + last_wireguard_sent_bytes_total else wireguard_sent_bytes_total = new_wireguard_sent_bytes_total

For wireguard_received_bytes_totall: If new_wireguard_received_bytes_total < last_wireguard_received_bytes_total then wireguard_received_bytes_total = new_wireguard_received_bytes_total + last_wireguard_received_bytes_totall else wireguard_received_bytes_tota l= new_wireguard_received_bytes_total

For wireguard_latest_handshake_seconds:l: If new_wireguard_latest_handshake_seconds > last_wireguard_latest_handshake_seconds then wireguard_sent_bytes_total = last_wireguard_sent_bytes_total else wireguard_latest_handshake_seconds = new_wireguard_latest_handshake_seconds

What do you think?