-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.sh
37 lines (30 loc) · 1.27 KB
/
metrics.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
echo 'status: 200'
echo 'content-type: text/plain'
echo ''
if [[ $(wg show wg0 peers | wc -l) -ne 0 ]]
then
echo '# HELP wireguard_sent_bytes_total Bytes sent to the peer'
echo '# TYPE wireguard_sent_bytes_total counter'
while IFS= read -r line; do
peer=$(echo $line | awk '{ print $1 }')
value=$(echo $line | awk '{ print $7 }')
echo "wireguard_sent_bytes_total{public_key=\"$peer\"} $value"
done <<< $(wg show wg0 dump | sed 1d)
echo ''
echo '# HELP wireguard_received_bytes_total Bytes received from the peer'
echo '# TYPE wireguard_received_bytes_total counter'
while IFS= read -r line; do
peer=$(echo $line | awk '{ print $1 }')
value=$(echo $line | awk '{ print $6 }')
echo "wireguard_received_bytes_total{public_key=\"$peer\"} $value"
done <<< $(wg show wg0 dump | sed 1d)
echo ''
echo '# HELP wireguard_latest_handshake_seconds Seconds from the last handshake'
echo '# TYPE wireguard_latest_handshake_seconds counter'
while IFS= read -r line; do
peer=$(echo $line | awk '{ print $1 }')
value=$(echo $line | awk '{ print $5 }')
echo "wireguard_latest_handshake_seconds{public_key=\"$peer\"} $value"
done <<< $(wg show wg0 dump | sed 1d)
fi