arw_monitor.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. source /etc/profile
  3. cur_time=$(date "+%Y-%m-%d-%H-%M-%S")
  4. echo $cur_time "-1" >> /mnt/xyzshop/util/a.log
  5. df_dirs=(${XYZ_DF_DIRS//:/ })
  6. du_dirs=(${XYZ_DU_DIRS//:/ })
  7. echo $cur_time "-2" >> /mnt/xyzshop/util/a.log
  8. echo $XYZ_DF_DIRS "-2" >> /mnt/xyzshop/util/a.log
  9. echo $cur_time "-2" >> /mnt/xyzshop/util/a.log
  10. declare -A reports
  11. reports=(['cur_time']=$cur_time)
  12. function df_check() {
  13. # shellcheck disable=SC2068
  14. for dir in ${df_dirs[@]}
  15. do
  16. ret=$(df -h | grep $dir | awk 'BEGIN{OFS=","}{print $2,$4}')
  17. key=${dir////_}
  18. reports[$key]=$ret
  19. done
  20. }
  21. function du_check() {
  22. # shellcheck disable=SC2068
  23. for dir in ${du_dirs[@]}
  24. do
  25. cd $dir
  26. ret=$(du -h -d 0)
  27. key=${dir////_}
  28. reports[$key]=$ret
  29. done
  30. }
  31. df_check
  32. echo $cur_time "-3" >> /mnt/xyzshop/util/a.log
  33. du_check
  34. echo $cur_time "-4" >> /mnt/xyzshop/util/a.log
  35. str_report=''
  36. for key in $(echo ${!reports[*]})
  37. do
  38. str_report="$str_report#$key:${reports[$key]}"
  39. done
  40. echo $str_report >> /mnt/xyzshop/util/a.log
  41. redis_host=$XYZ_REDIS_HOST
  42. netip=$XYZ_NETIP
  43. echo "HSET nc_disk_monitor $netip '$str_report'" | redis-cli -h $redis_host -p 6379
  44. echo $cur_time "-6" >> /mnt/xyzshop/util/a.log