[ale] monitoring memory

Jay Loden ale at jayloden.com
Wed Oct 24 20:13:23 EDT 2007


There are a large number of tools you can use for this. Some that come to mind that I have past experience with: 

1) free (subtracting cache/buffer gives you real free mem)
2) top
3) /proc/meminfo
4) SNMP agent (if you want to monitor from a network monitoring system e.g. nagios)


For instance, this would give you the total free memory in MB by parsing /proc/meminfo directly:

  total=0; for i in `egrep 'MemFree:|Buffers:|^Cached:' /proc/meminfo \
    | awk '{print $2}'`; do total=$(($total + $i)); done \
    && echo $(($total / 1024))

I'm sure there are other ways to do it which make for an interesting exercise in shell scripting or perl fu :) For MySQL itself, I've had reason in the past to need to calculate the MySQL total memory usage also, so I hacked up a simple command/script that gives the MySQL process total memory usage (also in MB). Unfortunately, I don't have that handy at the moment but I will post back to the list when I can find a copy of it. 

In basic terms, you can use free, top, or the proc meminfo stats to get overall system memory utilization statistics, and if you want memory utilization for a specific PID the easiest way I know of is using pmap, which is available on many Linux distros.

Hope some of this helps,

-Jay


John Heim wrote:
> I'm managing a web server  that runs a application written in mod_perl with 
> a mysql backend. I've had problems running out of memory.
> We've had occasional OOM events and we've also had mysql crashes due to 
> exceeding the maximum number of allowed connections.
> 
> I've tweeked the apache and mysql settings but what I'd really like to know 
> is if there is some way to tell if I'm close to running out of RAM.
> 
> Would the load average be a clear sign? Any other tools? How about 'free'?
> 
> Notes:
> I didn't write this software and can't alter it. I figure what's happening 
> is that the mysql connections never get closed. They timeout eventually.
> 
> When it ran out of mysql connections, I increased the max_connections from 
> 100 to 250. But since I'd already seen OOM events in the past, I figured I'd 
> see even more after changing that. So I set the mysql timeout to 60 
> seconds -- which, btw, defaults to 8 hours -- and i decreased the apache 
> max_ maxClients setting from the default of 150 to 32.
> 
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list