A handy script to which you can pass a single or multiple hostnames and in turn it fetches server stats of those remote systems namely Uptime & Load Avg, CPU Usage, Memory Usage, list of disks running out of space and list of hungry processes. In case you have not yet in an ansible managed environment, scripts such as this will be a time saver.


fork-git

#!/bin/bash
    clear
    echo "Enter Hostname(s) with space in between"
    echo "Type 'X' to exit"
    read -a Hostname
      if [ "${Hostname[0]}" == x ] || [ "${Hostname[0]}" == X ]; then
       :
      else
        for i in "${Hostname[@]}"
          do
             ssh -T -o ConnectTimeout=10 -o ConnectionAttempts=1 $i <<'EOF'
             # if you need to ssh as different user replace 'username' with the actual username 
             # ssh -T -o ConnectTimeout=10 -o ConnectionAttempts=1 username@$i <<'EOF'
                     echo "Generated on", $(date)
                     echo "-----Hostname & OS-----"
                     hostname
                     uname
                     cat /etc/*release 2> /dev/null
                     echo ""
                     echo "-----Uptime & Load Avg-----"
                     uptime
                     echo ""
                     echo "-----CPU Usage-----"
                     top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{n=split($1, vs, ","); v=vs[n]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }'
                     echo ""
                     echo "-----Memory Usage-----"
                     echo `free | awk 'FNR == 3 {print $3/($3+$4)*100}'`%
                     echo ""
                     echo "-----Mount points with 90%+ disk usage-----"
                     echo "Filesystem            Size  Used Avail Use% Mounted on"
                     df -Ph | awk '0+$5 >= 90 {print}'
                     echo ""
                     echo "-----Top Processess-----"
                     echo "USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND"
                     ps auxf | sort -nr -k 4 | head -10
                     echo ""
EOF
           done >> server_stats_op.`date +%Y-%m-%d%H%M%S`.txt
      fi

The output of the script should prompt for hostnames/IP to fetch the details from.

Enter Hostname(s) with space in between
Type 'X' to exit