arw_monitor.sh 813 B

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