lots of stuff

This commit is contained in:
bee
2026-08-16 14:48:04 +02:00
parent c63db540e8
commit 49fa352476
45 changed files with 32520 additions and 93 deletions
@@ -0,0 +1,60 @@
#!/bin/bash
set -uo pipefail
textfile_dir={{ node_exporter_textfile_dir }}
file=${textfile_dir}/wireguard.prom
tmp=${file}.$$
now=$(date +%s)
mkdir -p ${textfile_dir}
peer_name() {
case "$1" in
{% for key, name in wireguard_peer_names.items() %}
"{{ key }}") echo "{{ name }}" ;;
{% endfor %}
*) echo "unknown" ;;
esac
}
{
echo "# HELP wireguard_peer_last_handshake_seconds Unix time of the last handshake with a peer."
echo "# TYPE wireguard_peer_last_handshake_seconds gauge"
echo "# HELP wireguard_peer_handshake_age_seconds Seconds since the last handshake with a peer."
echo "# TYPE wireguard_peer_handshake_age_seconds gauge"
echo "# HELP wireguard_peer_up Whether a peer handshaked within the last five minutes."
echo "# TYPE wireguard_peer_up gauge"
echo "# HELP wireguard_peer_receive_bytes_total Bytes received from a peer."
echo "# TYPE wireguard_peer_receive_bytes_total counter"
echo "# HELP wireguard_peer_transmit_bytes_total Bytes sent to a peer."
echo "# TYPE wireguard_peer_transmit_bytes_total counter"
wg show all dump 2>/dev/null | awk 'NF >= 8' | while read -r interface key psk endpoint allowed handshake rx tx keepalive
do
name=$(peer_name "${key}")
labels="interface=\"${interface}\",peer=\"${name}\""
age=$((now - handshake))
up=0
if [ "${handshake}" -gt 0 ] && [ "${age}" -lt 300 ]
then
up=1
fi
if [ "${handshake}" -eq 0 ]
then
age=-1
fi
echo "wireguard_peer_last_handshake_seconds{${labels}} ${handshake}"
echo "wireguard_peer_handshake_age_seconds{${labels}} ${age}"
echo "wireguard_peer_up{${labels}} ${up}"
echo "wireguard_peer_receive_bytes_total{${labels}} ${rx}"
echo "wireguard_peer_transmit_bytes_total{${labels}} ${tx}"
done
} > "${tmp}"
chmod 0644 "${tmp}"
mv "${tmp}" "${file}"