Wednesday, May 8, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 838  / 3 Years ago, fri, may 7, 2021, 9:45:18

Using the top -b -n1 command I can get the resources utilised by my system for that instance. However, I actually need specific values out of it. I need things like, overall CPU usage, overall memory usage, and the top 5 processes using the cpu resources for that instance.
Currently I am able to find:



Cpu usage: top -b -d1 -n1|grep -i 'Cpu(s)'|head -c21|cut -d '' -f3|cut -d '%' -f1



Top 5 process : ps aux | sort -nrk 3,3 | head -n 5



I am unable to work out something for the Ram usage. I am trying commands something like in the Cpu usage command, but it returns me nothing. To be frank, I am unable to cut it out properly. Some help in retrieving that is appreciated.



Extra Help: Also, on the same grounds, is it possible to get the mac address of the system. Like a command that might just return me the mac address and not 100s of lines that I need to manipulate.



Thank you for the help.


More From » command-line

 Answers
5

Total RAM Usage:



This command will return your RAM total usage as GB:



free -h |grep Mem| cut -c 20-32 | sed -e 's/^[ 	]*//'


This will return your RAM total usage as Bytes (just remove the -h):



free |grep Mem| cut -c 20-32 | sed -e 's/^[ 	]*//'


This will report the percentage of memory in use



free | grep Mem | awk '{print $3/$2 * 100.0}'


This will report the percentage of memory that's free



free | grep Mem | awk '{print $4/$2 * 100.0}'


MAC Address:



If you want to output ONLY the mac address of a specific device, you can do this (replace "wlp2s0" with the name of your network interface):



nmcli -t -f GENERAL.HWADDR device show wlp2s0 | sed 's/GENERAL.HWADDR://'

[#5137] Sunday, May 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hentor

Total Points: 482
Total Questions: 104
Total Answers: 111

Location: South Korea
Member since Sun, Dec 25, 2022
1 Year ago
;