Script to execute command if memory usage is over + a question
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Script to execute command if memory usage is over + a question
I need a script, that executes a command if memory usage on the machine is over 60%. I have a problem with apache and there's a memory leak which I can't locate. And that's the second question. How could I locate which process is causing the leak?
At least twice a day memory usage goes up to 100% until I dont reload or restart the httpd.
The script I need is not a real solution, but it should work..
My best advice would be to write a shell script to do what you want, and then at the top put a test to see how much memory is used and exit if memory usage is OK, e.g.:
Code:
#!/bin/bash
threshold=256 # replace this with the max amount of non-buffer/cache memory you expect to be used in MB
mbused=`free -m | grep "^-/+" | awk '{print $3}'`
if [ "$mbused" -lt "$threshold" ]; then exit; fi
## perform whatever action you want to take when mem use is above normal here
Then run this script from cron every 1-5 minutes at your discretion.
It's not terribly clean, but it's the best way I know to accomplish what you want to do.
Last edited by btmiller; 01-19-2013 at 11:46 AM.
Reason: mistake is script
I have a problem with apache and there's a memory leak which I can't locate. (..) How could I locate which process is causing the leak?
Start by collecting system statistics using any SAR like Atop, Collect, Dstat, Atsar or just plain sysstat. Having that data will show you resource usage over time wrt bottlenecks and will serve as a baseline against you can measure the effect of any changes you make. Then start listing / exploring your HW specs, what web server, interpreter, database software your LAMP comprises of, what runs on top of your web server interpreter-wise (Perl, PHP, Python, Java, Ruby, etc), software (web forum, shopping cart, web log, photo gallery, statistics, homebrewn software) including any plugins, then check each software packages version against what the vendor marks as outdated / supported + current, check your web server, interpreter, database configuration for unwanted or unnecessary items, their log files for clues and tell us when you first noticed what you think is a memory leak and what measures you already took.
I need a script, that executes a command if memory usage on the machine is over 60%. I have a problem with apache and there's a memory leak which I can't locate. And that's the second question. How could I locate which process is causing the leak?
At least twice a day memory usage goes up to 100% until I dont reload or restart the httpd.
The script I need is not a real solution, but it should work..
There is MaxRequestsPerChild configuration option for Apache.
If you limit requests number for each worker process, then you'll limit your memory leak.
After process exited all resources - leaked included - will be freed
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.