| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/bin/bash
- function 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)
- 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"
- }
- count=$(ps aux | grep "$0" | grep -v grep | wc -l)
- if [ "$count" -gt 2 ]; then
- exit 0
- fi
- online &
- bw &
- drops &
- wait
|