| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/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}'
- }
- function log {
- curl -s -i -XPOST 'http://graphs.eba:8086/write?db=curso' --data-binary "$1" >/dev/null
- }
- function online {
- cuantos=$(ssh especificosba.com.ar './cuantos_online.sh')
- log "curso,type=online value=$cuantos"
- }
- function drops {
- drops=$(ssh especificosba.com.ar "find /var/videos -type f -mmin -10 | wc -l")
- drops=$(echo $drops-1 | bc)
- if [ $drops -lt 0 ]; then
- drops=0
- fi
- log "curso,type=drops value=$drops"
- }
- function bw {
- running=$(ps aux | grep voctocore | grep -vc grep)
- if [ $running -ne 1 ]; then
- sleep 60
- return
- fi
- 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 |\
- 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
- }
- online &
- bw &
- drops &
- wait
|