From bb26f900b120257224fb6dea06b88c0f88fb1e15 Mon Sep 17 00:00:00 2001 From: Artem Zavyalov Date: Thu, 21 Mar 2024 15:30:26 -0700 Subject: [PATCH] Update plugins/wireguard/wireguard_ Co-authored-by: Pim --- plugins/wireguard/wireguard_ | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/wireguard/wireguard_ b/plugins/wireguard/wireguard_ index fd3b3505..a6636a46 100755 --- a/plugins/wireguard/wireguard_ +++ b/plugins/wireguard/wireguard_ @@ -169,16 +169,13 @@ EOF echo "multigraph wireguard_peercount" for iface in $(wg_interfaces); do threshold=$(date --date="10 min ago" +%s) - isactive=0 - for line in $(wg_peers "$iface"); do - handshake=$(echo "$line" | tr ';' ' ' | awk '{print $5}') - if [[ "handshake" -gt "threshold" ]]; then - isactive=$((isactive + 1)) - fi - done + iface_peers=$(wg_peers "$iface") - echo "pc_on_$iface.value $(wg show "$iface" peers | wc -l)" - echo "pc_on_active_$iface.value $isactive" + peer_count=$(wc -l <<< "$iface_peers") + active_peer_count=$(awk -F";" -v threshold=$active_threshold '$5 > threshold' <<< "$iface_peers" | wc -l) + + echo "pc_on_$iface.value $peer_count" + echo "pc_active_on_$iface.value $active_peer_count" done echo ""