On Saturday 28 March 2009 22:48:53 Chuck Payne wrote:
Guys,
I have a question about memory, where I work we have been having heated debates about how to monitor memory in Linux. I am tasked to write a bash script that will alert me when our server are pegged using memory.
I have been doing this to take a look at how much memory has been used.
free -o -m total used free shared buffers cached Mem: 1134 1094 39 0 299 325 Swap: 2288 0 2288
I have been taking the total - cached = total memory used.
Almost. It's total - cached - buffers - free = memory used (or a close approximation of it). If you don't use the -o switch, you get it pre-calculated
free total used free shared buffers cached Mem: 6115016 6082736 32280 0 98812 4404988 -/+ buffers/cache: 1578936 4536080 Swap: 2096472 140 2096332
So on this machine I have used about 1.5GB (first number on second line) out of a total of 6 (first number on first line), and the free memory is roughly 4.5GB (second number on second line)
I found this script but every time it check it sends an alert that memory is over 90%, and that not good to get a lot of false alarms.
Yes, the script doesn't take into account the fact that linux uses unused memory for buffers and cache. This memory is not included in the "free" value, because it technically isn't (it's used internally by the kernel), but it is available, because as soon as an application needs it, the buffers get flushed and caches dropped - at least enough to accommodate the application.
Does any one have a good script I can use, or can advise me on what is best practise for monitor memory.
There are tools for monitoring systems that were written by people who understand linux memory management. If you want to write your own script, you can just monitor for when the "free" value on the "-/+ buffers/cache" line gets too low, but I would recommend using one of the existing monitoring tools. For example, have a look at nagios Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org