Get percentage of use of RAM and DISK in Linux

1

Basically I would like to know the command in linux to get "ONLY THE PERCENTAGE OF USE" of RAM and DISK. I emphasize "ONLY THE PERCENTAGE" because I would like to save this value in a String without first doing any treatment.

I would greatly appreciate your collaboration. Greetings and thanks.

    
asked by Luis Ramiro 10.05.2018 в 00:56
source

1 answer

1

After so many attempts and to read as many post I managed to decipher as just returning the% of CPU, RAM and DISK usage. and the commands that served me were the following:

CPU:

grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'

MEMORY:

free -m -h -t | grep T | awk '{usage=($3*100)/$2} END {print usage "%"}'

DISK:

df --total | awk '{usage=($4*100)/$2} END {print usage "%"}'

Thank you very much to all those who in one way or another helped me. Greetings.

    
answered by 10.05.2018 в 21:57