Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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]: "
swann:/home/dspillett# egrep '^MemTotal:|^MemFree:|^Buffers:|^Cached:' /proc/meminfo   | tr -d "[A-Z][a-z]: "

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


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.