1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #!/bin/bash
- source /etc/profile
- cur_time=$(date "+%Y-%m-%d-%H-%M-%S")
- df_dirs=(${XYZ_DF_DIRS//:/ })
- du_dirs=(${XYZ_DU_DIRS//:/ })
- declare -A reports
- reports=(['cur_time']=$cur_time)
- function df_check() {
- # shellcheck disable=SC2068
- for dir in ${df_dirs[@]}
- do
- ret=$(df -h | grep $dir | awk 'BEGIN{OFS=","}{print $2,$4}')
- key=${dir////_}
- reports[$key]=$ret
- done
- }
- function du_check() {
- # shellcheck disable=SC2068
- for dir in ${du_dirs[@]}
- do
- cd $dir
- ret=$(du -h -d 0)
- key=${dir////_}
- reports[$key]=$ret
- done
- }
- df_check
- du_check
- str_report=''
- for key in $(echo ${!reports[*]})
- do
- str_report="$str_report#$key:${reports[$key]}"
- done
- redis_host=$XYZ_REDIS_HOST
- netip=$XYZ_NETIP
- echo "HSET nc_disk_monitor $netip '$str_report'" | redis-cli -h $redis_host -p 6379
|