LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 08-05-2010, 08:10 AM   #1
koshihaku
Member
 
Registered: Aug 2010
Posts: 50

Rep: Reputation: 0
Smile Need help about monitoring process memory


Hi,

I am a student doing a experiment. I need to obtain the memory usage (RSS or real) of Apache httpd process every couple of seconds and write it to a log file.

I need to record the time from beginning to receive http requests from the only client to the time when the Apache httpd memory reaches 90% of total memory.

I'm thinking of writing a perl script. What commands and/or monitoring software are available for this task?

Thanks,

My experiment includes one host: Ubuntu Apahce2, one client: Ubuntu connected by switch

Last edited by koshihaku; 08-05-2010 at 10:17 PM.
 
Old 08-05-2010, 08:09 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,095
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
pmap would work but it's kind of noisy

pmap -x and just look at the mid number of the last line that's total RSS
 
Old 08-05-2010, 09:01 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,359

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Better to use /proc/<pid>/status and grep VmRSS - lot easier to handle. Both include the shared libraries, so you could debate whether it *really* is the real usage of that task. And when/if it gets to 90% of total will be highly contentious.
 
1 members found this post helpful.
Old 08-05-2010, 09:24 PM   #4
koshihaku
Member
 
Registered: Aug 2010
Posts: 50

Original Poster
Rep: Reputation: 0
Question

Quote:
Originally Posted by syg00 View Post
Better to use /proc/<pid>/status and grep VmRSS - lot easier to handle. Both include the shared libraries, so you could debate whether it *really* is the real usage of that task. And when/if it gets to 90% of total will be highly contentious.
Thank you! by the way, can I get the memory used every couple of seconds?
 
Old 08-05-2010, 10:25 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,359

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
/proc is not a real filesystem despite what it appears. It is a pseudo filesystem, the contents of which are created ("filled in" if you like) by kernel code when you "read" the file.
Read it as often as you wish - the contents will always be correct at that instant in time.
 
Old 08-06-2010, 01:45 AM   #6
koshihaku
Member
 
Registered: Aug 2010
Posts: 50

Original Poster
Rep: Reputation: 0
Here is a script written by someone. How can I revise this one to meet my requirement?

I am sorry for basic questions, but I am a newbie....


#!/bin/sh
PROCNAME=httpd
SYSDATE=`date -d today +"%Y-%m-%d %H:%M:%S"`
NUM=$(ps -ef | grep $PROCNAME | wc -l)
echo -n $SYSDATE >> /root/apache_monitor.log
echo -n ' NUM:' >> /root/apache_monitor.log
echo $NUM >> /root/apache_monitor.log


Maybe I can change some commands in it, can make this run every few seconds, but how can I achieve this? Thanks alot
 
Old 08-06-2010, 02:22 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,359

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
You're not going to learn much if others do it all for you.
We're here to nudge you in the right direction.
 
Old 08-10-2010, 02:36 AM   #8
koshihaku
Member
 
Registered: Aug 2010
Posts: 50

Original Poster
Rep: Reputation: 0
I am running the following code and receiving the warning :


Use of uninitialized value in pattern match (m//) at processMonitor.pl line 38


\processMonitor.pl

#!/usr/bin/perl -w
#
#name: processMonitor.pl
#written by trizsolo
#usage: ./processMonitor.pl args args args
#you can add as many processes as needed for args
#or use the defaults... syslogd is always checked
#----------------------------
my $user='root';
my $host=`hostname`;
chomp($host);
my $date=`date`;
chomp($date);
my $logfile="$host" . '.log';
our @proc_list=@ARGV;
# Default list of processes
if(@proc_list==0){ # check for arguments
@proc_list=('inetd', 'sendmail', 'chkMounts.pl');
}
push(@proc_list, 'syslogd'); # add syslogd to check

# ---------- open logfile and determine Operating System --------------
open(LOG, ">>$logfile") or die "Can't open $logfile to write: $!";
print LOG "Searching for: @proc_list on $date!\n";
chomp($os=`uname -r`);
print LOG "OS on this server is $os\n";
close(LOG);

# ---------------- call "ps" & analyse output --------------------
foreach my $process (@proc_list) {
$event_count{$process} = 0;
}
open(PS, "/bin/ps auwx |") or die "Can't run ps: __FILE__ $!";
$/="\n"; # record seperator
while(
) {
foreach my $process(@proc_list) {
if($_ =~(m/$process/i)) {
$event_count{$process}++;
}
}
}
close(PS);
open(LOG,">>$logfile") or die "Cannot open $logfile: $!";
# Add line to log to nagios if needed
foreach $process(@proc_list) {
if($event_count{$process} ==0) {
print LOG "Process $process is NOT running!\n";
system("/bin/logger -p warn Process: $process is NOT running!\n")
== 0 or die "Cannot complete cmd: $! : $?";
}else{
print LOG "Process $process occurred $event_count{$process} times!\n";
}
}
close(LOG);
exit 0;
#EOF

please help
 
Old 08-11-2010, 06:39 AM   #9
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,095
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
I'd guess it's because you don't have a space between $process and (@proc_list) though you'd think in that case it'd say the foreach was bad. Also Code tags help keep formatting [ CODE ] [ /CODE ] but without the extra internal spaces
 
  


Reply

Tags
apache, httpd, monitoring, rss


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
process, memory, swap, virtual memory wakatana Linux - Hardware 1 08-31-2009 07:55 AM
Monitoring process CPU and Memory usage jdt05 Programming 5 05-02-2008 08:10 AM
Monitoring free memory with enterprise monitoring application Steelb Linux - Enterprise 2 02-13-2008 10:10 AM
memory monitoring in-process mmeijer Programming 2 07-14-2006 11:00 AM
Help Configuring the Memory Used by a Process in RedHat? (Cache Memory on CPU) geogecko Linux - General 3 02-23-2005 03:32 PM


All times are GMT -5. The time now is 11:22 PM.

Main Menu
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