Obtaining Usage Information on *nix Systems

When obtaining usage information, there are primarily 3 details you want to look at (for my needs, yours may vary) being CPU, RAM, Hard Disk. On many systems you can use the below commands:

cat /proc/cpuinfo | grep processor | wc -l
free
df -h

On newer machines ( I think RHEL 6 and newer) you can use nproc in place of the first command:

nproc
free
df -h

There is also this very straight forward method below:

HOSTNAME=$(hostname | tr [A-Z] [a-z] | sed -e 's/.example.com//'); PROCS=$(cat /proc/cpuinfo | grep processor | wc -l); MEMTOTAL=$(echo "scale = 2; $(free | grep 'Mem:' | awk '{print $2}')/1048576" | bc); MEMUSED=$(echo "scale = 2; $(free | grep 'Mem:' | awk '{print $3}')/1048576" | bc); HDTOTAL=$(df -h | grep -v 'nas' | grep "/\$" | awk '{print $1}'); HDUSED=$(df -h | grep -v 'nas' | grep "/\$" | awk '{print $2}'); echo -e '\n\n'$HOSTNAME':\nCPU: '$PROCS' cores\nRAM: '$MEMUSED'G Used / '$MEMTOTAL'G Total\nHD: '$HDUSED' Used / '$HDTOTAL' Total\n'

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *