hosts=`cat /etc/hosts | grep -e 'ta[0-9]' | awk '{print $2}'`;
ifAlert='false'
min=256
minHost=''
for host in $hosts
do
    available=`ssh $host free -g | grep 'Mem:' | awk '{print $7}'`
    hard_limit=`curl $host:8050/varz 2>/dev/null | grep memory_limit_hard_bytes | awk -F '=' '{print $2}'` 
    used=`ssh $host ps -aux | grep kudu-tserver | grep gflagfile | awk '{print $6}'`
    if [ -z "$available" ] || [ -z "$hard_limit" ] || [ -z "$used" ] ;then
        echo "Failed to get the statistics of $host, the tserver might not exist." >> /root/scan.log
        continue
    fi
    remain=`echo "$available - (($hard_limit / 1024) - $used) / 1024 / 1024" | bc`
    echo "$host remain memory is ${remain}G" >> /root/scan.log
    if [ $remain -lt 5 ] ;then
        ifAlert='true'
        if [ $remain -lt $min ] ;then
            min=$remain
            minHost=$host
        fi
    fi
done
if [ $ifAlert == 'true' ]; then
    echo "本环境存在kudu超配问题,最严重的机器是$minHost,内存剩余值为${min}G"
fi