oliverthered

zipio.sh

Sep 4th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.94 KB | None | 0 0
  1. loadthreashold=2.05
  2. ioprocthreshold=20
  3. cpuprocthreashold=20.0
  4. cpuprocreset=5.0
  5. reniceto=10
  6. while true
  7. do
  8. i=$(cut -d ' ' -f 1 /proc/loadavg)
  9. if [ $i > $loadthreashold ]
  10. then
  11.     echo  "Load \"$i\" exceeds threashold of $loadthreashold"
  12. for i in $(iotop -P -b -q -o -d 0.1 -n 5 | awk -F ' ' "{if ( \$1 ~ /[0-9]/ && \$10 > $ioprocthreshold && \$2 == "be/0") print  \$1}")
  13. do
  14.        ionice -c 3 -p $i
  15.        echo "process $i reniced to idel as it was hogging io"  
  16. done
  17. for i in $(top  -b -d 0.1 -n 5 | awk -F ' ' "{if ( \$1 ~ /[0-9]/ && \$4 == 0 && \$9 > $cpuprocthreashold) print  \$1}")
  18. do
  19.        renice -n $reniceto -p $i
  20.        echo "process $i reniced to $reniceto as it was hogging cpu"    
  21. done
  22. for i in $(top  -b -d 0.1 -n 1 | awk -F ' ' "{if ( \$1 ~ /[0-9]/ && \$4 == $reniceto && \$9 < $cpuprocreset) print  \$1}")
  23. do
  24.        renice -n 0 -p $i
  25.        echo "process $i reniced to 0 as it stopped hogging cpu"
  26. done
  27. fi
  28. sleep 1
  29. done
  30.  
Advertisement
Add Comment
Please, Sign In to add comment