LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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



Reply
 
Search this Thread
Old 01-19-2013, 12:25 PM   #1
ps1x0
Member
 
Registered: Jan 2011
Posts: 35

Rep: Reputation: 0
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..
 
Old 01-19-2013, 12:45 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,167

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
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 12:46 PM. Reason: mistake is script
 
Old 01-19-2013, 03:18 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,818
Blog Entries: 54

Rep: Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991Reputation: 2991
Quote:
Originally Posted by ps1x0 View Post
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.
 
Old 01-20-2013, 04:11 PM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 670

Rep: Reputation: 134Reputation: 134
Quote:
Originally Posted by ps1x0 View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What command can I use to see the memory usage by application EdJulien Linux - Newbie 6 11-09-2012 02:53 PM
script to monitor memory and cpu usage s_linux Suse/Novell 3 07-23-2009 03:03 PM
TOP command: calculation of memory usage samiralmousawi Linux - Server 7 07-29-2008 04:16 PM
Script for Memory Usage?? ajeetraina Linux - Server 6 03-31-2008 10:27 AM
checking memory usage from command line wrepti Linux - General 2 06-16-2004 11:24 PM


All times are GMT -5. The time now is 04:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration