[SOLVED] Need help about monitoring process memory
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
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
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.
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?
/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.
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.