Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i've simple question . how i can customize the display of free or vmstat or top commands to display memory usage only because i want the result to draw it via MRTG .

share|improve this question

3 Answers 3

up vote 2 down vote accepted

You could pass the contents of /proc/meminfo through grep to get the lines you want. For instance:

swann:/home/dspillett# grep MemTotal /proc/meminfo
MemTotal:      6099676 kB
swann:/home/dspillett# grep ^Cached /proc/meminfo
Cached:        5418912 kB

(the ^ in the command looking for "cached" tells grep to only match at the start of a line, so it won't find the line for the SwapCached value too)

Or if you want more than one line at once, use the extended matching option so the "or" operator can be used:

swann:/home/dspillett# egrep '^MemTotal:|^MemFree:|^Buffers:|^Cached:' /proc/meminfo
MemTotal:      6099676 kB
MemFree:         37596 kB
Buffers:         73084 kB
Cached:        5418912 kB

You can use tr to return just the numeric values for a single item:

swann:/home/dspillett# grep MemTotal /proc/meminfo | tr -d "[A-Z][a-z]: "
6099676
swann:/home/dspillett# egrep '^MemTotal:|^MemFree:|^Buffers:|^Cached:' /proc/meminfo   | tr -d "[A-Z][a-z]: "
6099676
182808
75488
5276000

There are a small pile of other standard text manipulation programs (cut, paste, sed, awk, xargs...) that you can pipe the results through to get the output into different formats. If you give the format you require in your question, if you are not looking for just a single numeric value in which case the above will do what you want, we can tell you which filters to pass the info through to get the desired result. I don't use MRTG myself so I can only guess the input format it requires.

share|improve this answer

/proc/meminfo contains all the various memory statistics, and you can grab the values from there and manipulate to your heart's content.

share|improve this answer

This isn't strictly speaking an answer to your question, but if you have a /proc filesystem, you might be able to grep out the information you're interested in from /proc/meminfo.

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.