LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 11:25 AM   #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, 11:45 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
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
 
Old 01-19-2013, 02:18 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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, 03:11 PM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
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



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 01:53 PM
script to monitor memory and cpu usage s_linux SUSE / openSUSE 3 07-23-2009 02:03 PM
TOP command: calculation of memory usage samiralmousawi Linux - Server 7 07-29-2008 03:16 PM
Script for Memory Usage?? ajeetraina Linux - Server 6 03-31-2008 09:27 AM
checking memory usage from command line wrepti Linux - General 2 06-16-2004 10:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:24 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
Open Source Consulting | Domain Registration