|
|
@@ -1,6 +1,6 @@
|
|
|
#!/bin/bash
|
|
|
deh() {
|
|
|
- echo $1 | awk '/[0-9]$/{print $1;next} /MB$/{printf "%u\n", $1*(1024*1024);next} /KB$/{printf "%u\n", $1*1024}'
|
|
|
+ echo "$1" | awk '/[0-9]$/{print $1;next} /MB$/{printf "%u\n", $1*(1024*1024);next} /KB$/{printf "%u\n", $1*1024}'
|
|
|
}
|
|
|
|
|
|
function log {
|
|
|
@@ -14,7 +14,7 @@ function online {
|
|
|
|
|
|
function drops {
|
|
|
drops=$(ssh especificosba.com.ar "find /var/videos -type f -mmin -10 | wc -l")
|
|
|
- drops=$(echo $drops-1 | bc)
|
|
|
+ drops=$(echo "$drops-1" | bc)
|
|
|
if [ $drops -lt 0 ]; then
|
|
|
drops=0
|
|
|
fi
|
|
|
@@ -30,18 +30,20 @@ function bw {
|
|
|
TIME=10
|
|
|
|
|
|
tmp=$(mktemp)
|
|
|
- #$6 is accumulated, $5 is avg over the last (up to) 40s
|
|
|
- iftop -P -b -B -n -i vmbr0 -N -t -s $TIME 2>/dev/null >$tmp
|
|
|
- python3 /root/parse_iftop.py $tmp |\
|
|
|
+ iftop -P -b -B -n -i vmbr0 -N -t -s "$TIME" 2>/dev/null >"$tmp"
|
|
|
+ python3 /root/parse_iftop.py "$tmp" |\
|
|
|
while read -r line; do
|
|
|
ip=$(echo $line | cut -d' ' -f 1)
|
|
|
data=$(echo $line | cut -d' ' -f 2)
|
|
|
log "curso,type=bw,host=${ip} value=${data}"
|
|
|
done
|
|
|
|
|
|
- rm $tmp
|
|
|
+ rm "$tmp"
|
|
|
}
|
|
|
|
|
|
+if [ $(ps aux | grep "$0" | grep -vc grep) -gt 1 ]; then
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
online &
|
|
|
bw &
|
|
|
drops &
|