Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to diplay the Memory usage, Disk Usage and CPU Load in the following format:

Memory Usage: 33/512MB (6%)    
Disk usage: 4.2/20GB (23%) 
CPU Load: 0.01

How can I do that?

share|improve this question
    
Looks a lot like homework. Grab the data you need from /proc itself or from other commands then format it with awk, perl, or just bash. –  mikebabcock Mar 11 at 13:25
    
Welcome to Unix & Linux Stack Exchange! Please always include your OS. Solutions very often depend on the Operating System being used. Are you using Unix, Linux, BSD, OSX, something else? Which version? –  terdon Mar 11 at 16:26

5 Answers 5

Try this, it works on my Debian system, the details may vary depending on your the implementation of these tools that your OS uses:

#!/bin/sh
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%)\n", $3,$2,$3*100/$2 }'
df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}' 

If you save the above as a script and run it, you will get (example from my system):

$ ./foo.sh 
Memory Usage: 4986/7994MB (62.37%)
Disk Usage: 23/68GB (35%)
CPU Load: 0.78

Note that the script above is giving the disk usage for the / partition. You did not specify what you wanted so I'm guessing that's what you're after.

share|improve this answer
    
I tried with only awk github.com/rahulinux/scripts/blob/master/sys_info.sh –  Rahul Patil Mar 11 at 17:31
    
@RahulPatil looks good, why don't you post it? –  terdon Mar 11 at 18:00
1  
because it's just your copied ans. :D –  Rahul Patil Mar 12 at 4:42

Check atop.

Read this, https://lwn.net/Articles/387202/

See, enter image description here

You can see load of disk / memory / cpu by apps:

enter image description here

For example, disk usage:

enter image description here

atop gathered statistics in the directory /var/log/atop/ in binary format files per days. You could read a man page, there must be a way to extract needful information.

share|improve this answer

There's nothing to display exactly in your particular format, but these provide some of the info, as an alternative it's possible to read valuse from /proc and /sys.

free - quick overview

vmstat 1 shows system performance i/o stats

top dynamic

htop similar to top

share|improve this answer
    
Throw in my personal favourite, iostat. –  mikebabcock Mar 11 at 13:24

I think you need nagios help, for all this plugins/srcipts for nagios are already made and you can download and test without nagios installation.

share|improve this answer

If you are using solaris, check this out: showcpucount

This will give you an idea of how to go about writing your code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.