analytics.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. deh() {
  3. echo $1 | awk '/[0-9]$/{print $1;next} /MB$/{printf "%u\n", $1*(1024*1024);next} /KB$/{printf "%u\n", $1*1024}'
  4. }
  5. function log {
  6. curl -s -i -XPOST 'http://graphs.eba:8086/write?db=curso' --data-binary "$1" >/dev/null
  7. }
  8. function online {
  9. cuantos=$(ssh especificosba.com.ar './cuantos_online.sh')
  10. log "curso,type=online value=$cuantos"
  11. }
  12. function drops {
  13. drops=$(ssh especificosba.com.ar "find /var/videos -type f -mmin -10 | wc -l")
  14. drops=$(echo $drops-1 | bc)
  15. if [ $drops -lt 0 ]; then
  16. drops=0
  17. fi
  18. log "curso,type=drops value=$drops"
  19. }
  20. function bw {
  21. running=$(ps aux | grep voctocore | grep -vc grep)
  22. if [ $running -ne 1 ]; then
  23. sleep 60
  24. return
  25. fi
  26. TIME=10
  27. tmp=$(mktemp)
  28. #$6 is accumulated, $5 is avg over the last (up to) 40s
  29. iftop -P -b -B -n -i vmbr0 -N -t -s $TIME 2>/dev/null >$tmp
  30. python3 /root/parse_iftop.py $tmp |\
  31. while read -r line; do
  32. ip=$(echo $line | cut -d' ' -f 1)
  33. data=$(echo $line | cut -d' ' -f 2)
  34. log "curso,type=bw,host=${ip} value=${data}"
  35. done
  36. rm $tmp
  37. }
  38. online &
  39. bw &
  40. drops &
  41. wait