-
Notifications
You must be signed in to change notification settings - Fork 1
/
getnetstat
executable file
·51 lines (47 loc) · 2.18 KB
/
getnetstat
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
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# this is free software under the GPLv2
# Author: Christof Schulze, christof.schulze@gmx.net
#
#set -ix
URL=http://map.bb.ffm.freifunk.net/nodes.json
HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL="${COLLECTD_INTERVAL:-60}"
getdata() {
temp=$(/usr/bin/wget -q -O - "$URL")
totalnodes=$(echo $temp|/bin/grep -P -o "name.*?}"|/usr/bin/wc -l)
#onlinenodes=$(echo $temp|/bin/grep -P -o "name.*?}" |/bin/grep -c "online\": true")
onlinenodes=$(echo $temp|/bin/grep -P -o "online\": *true" |wc -l)
#clients=$(echo $temp|/bin/grep -P -o "name.*?}.*?}" |/bin/grep -o -P "clientcount\": [0-9]+"|/usr/bin/awk '{sum=sum+$2} END {print sum}')
clients=$(echo $temp|/bin/grep -P -o "client.........."|cut -d: -f2|cut -d, -f1|awk '{sum = sum + $1} END {print sum}')
# echo totalnodes: $totalnodes
# echo onlinenodes: $onlinenodes
# echo clients: $clients
echo "PUTVAL \"$HOSTNAME/exec-Freifunk_Frankfurt/gauge-Total_Nodes\" interval=$INTERVAL N:$totalnodes"
echo "PUTVAL \"$HOSTNAME/exec-Freifunk_Frankfurt/gauge-Online_Nodes\" interval=$INTERVAL N:$onlinenodes"
echo "PUTVAL \"$HOSTNAME/exec-Freifunk_Frankfurt/gauge-Online_Clients\" interval=$INTERVAL N:$clients"
echo "PUTVAL \"$HOSTNAME/exec-Freifunk_Frankfurt_Clients/gauge-Online_Clients\" interval=$INTERVAL N:$clients"
# fastdnodes=$(echo $temp|grep -o -P "name\": \"fastd.*?gateway\": true.*?}.*?}")
# IFS="
#"
#for fastd in $fastdnodes
#do
# mac=$(echo $fastd|grep -o -P "id\":.*?\"}"|awk '{print $2}'|sed 's/[\",}]//g')
# fname=$(echo $fastd|awk '{print $2}'|sed 's/[\",\,]//g')
# fconnect=$(echo $temp|grep -oP "links.*" |grep -o -P "id\":.*?}"|grep "vpn"|grep -c $mac)
# echo "PUTVAL \"${HOSTNAME:-fastd}/exec-Freifunk_Frankfurt/gauge-Connections_${fname:-name}\" interval=$INTERVAL N:${fconnect:-0}"
#done
while read line
do
fname=$(echo $line|awk '{print $2}'| tr -cd '[[:alnum:]]._-')
fconnect=$(echo $line|awk '{print $1}')
echo "PUTVAL \"${HOSTNAME:-fastd}/exec-Freifunk_Frankfurt/gauge-Connections_${fname}\" interval=$INTERVAL N:${fconnect:-0}"
done < <(echo $temp |jq ".nodes "|grep -e "fastd[0-9]"|grep -v null|sort |uniq -c)
}
[[ -z $1 ]] ||
{
getdata
exit 0
}
while sleep "$INTERVAL"; do
getdata
done