Skip to content

Instantly share code, notes, and snippets.

View jvinolas's full-sized avatar

Josep Maria Viñolas Auquer jvinolas

View GitHub Profile
@jbaiter
jbaiter / wg-monitor.py
Last active May 25, 2023 13:29
Structured Logging and Prometheus Exports for Wireguard sessions
#!/usr/bin/env python3
"""Wireguard logging and monitoring tool.
Logs the following events along with the peer state in JSON format to stdout:
- Peer connected (= successfull handshake after period of no handshakes)
- Peer disconnected (= no handshake for longer than 5 minutes)
- Peer roamed (= source IP of the peer changed)
Additionally, the tool exposes a Prometheus-compatible monitoring endpoint
on port 9000 that exports the following metrics: