checking memory and cpu consumption of procs
Voon, Ton
Ton.Voon at egg.com
Fri Dec 20 18:49:06 CET 2002
Copying onto nagiosplug-devel list. Future replies will only be to the
nagiosplug-devel list.
I would go with "Keep it simple". If a plugin reports a failure, then it is
the manual investigation that will show up the stderr failures. I would
think a ps failure is fairly catastrophic ;o)
Then again, maybe it is just the initial pain of a new model. I can see the
model makes more sense for plugins that call 3rd party commands. Maybe Karl
would be interested in adding runcmd in utils.c?
If your friends are going to look at this on Solaris, here's some of the
pain I discovered:
strsep is not supported on Solaris. A portable version is:
/***************************************************************************
***
* This is a replacement for strsep which is not portable (missing on
Solaris).
* From Wine code by François Gouget <fgouget at codeweavers.com>
*/
static char* getToken(char** str, const char* delims)
{
char* token;
if (*str==NULL) {
/* No more tokens */
return NULL;
}
token=*str;
while (**str!='\0') {
if (strchr(delims,**str)!=NULL) {
**str='\0';
(*str)++;
return token;
}
(*str)++;
}
/* There is no other token */
*str=NULL;
return token;
}
INFTIM is not supported either. Add this in check_cpu.c
#ifndef INFTIM
#define INFTIM (-1)
#endif
Here's my diff of configure.in. CPU_COMMAND should be defined within the ps
syntax checks, not at the end in your patch.
*** configure.in.beta2 Fri Dec 20 17:31:00 2002
--- configure.in Fri Dec 20 17:31:08 2002
***************
*** 260,265 ****
--- 260,266 ----
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(signal.h strings.h string.h syslog.h unistd.h uio.h
errno.h regex.h sys/types.h sys/time.h sys/socket.h sys/loadavg.h)
AC_CHECK_HEADERS(stdarg.h sys/unistd.h unistd.h ctype.h sys/wait.h
stdlib.h)
+ AC_CHECK_HEADERS(poll.h sys/poll.h asm/poll.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
***************
*** 528,533 ****
--- 529,536 ----
AC_DEFINE_UNQUOTED(VSZ_FORMAT,"%d %s",[])
AC_DEFINE_UNQUOTED(RSS_COMMAND,"$PATH_TO_PS -Ao 'rss comm'",[])
AC_DEFINE_UNQUOTED(RSS_FORMAT,"%d %s",[])
+ AC_DEFINE_UNQUOTED(CPU_COMMAND,"$PATH_TO_PS -Ao 'pcpu comm'",[])
+ AC_DEFINE_UNQUOTED(CPU_FORMAT,"%f %s",[])
echo " ps syntax... $PATH_TO_PS -Ao 's comm vsz rss'"
elif [ps -Ao 'status comm vsz rss uid user ppid args' 2>/dev/null | egrep
-i "^S[TAUES]* +C[OMDNA]+ +V[SIZE]+ +RSS +UID +USER +PPID +[RGSCOMDNA]+"
>/dev/null]
then
Here's how I put includes in plugins/common.h:
*** common.h.in.beta2 Fri Dec 20 12:29:51 2002
--- common.h.in Fri Dec 20 12:49:38 2002
***************
*** 66,71 ****
--- 66,81 ----
#include <signal.h>
#endif
+ #ifdef HAVE_POLL_H
+ #include <poll.h>
+ #endif
+ #ifdef HAVE_SYS_POLL_H
+ #include <sys/poll.h>
+ #endif
+ #ifdef HAVE_ASM_POLL_H
+ #include <asm/poll.h>
+ #endif
+
/* #ifdef HAVE_GETOPT_H */
#include <getopt.h>
/* #endif */
Ton
> -----Original Message-----
> From: Dave Viner [SMTP:dviner at yahoo-inc.com]
> Sent: Friday, December 20, 2002 5:09 PM
> To: Voon, Ton; nagios-users at lists.sourceforge.net
> Subject: RE: [Nagios-users] checking memory and cpu consumption of
> procs
>
> Hi Ton,
> I don't think I currently have access to a Solaris machine, but I'll
> try to
> ask some folks I know who do solaris development. I think using poll() or
> select() or something like that can provide functionality that the
> spopen()/fgets() strategy can't. In particular, imagine code that uses
> the
> spopen()/fgets() model and the popen_timeout_alarm_handler(). The command
> that is executed doesn't output anything to STDOUT, but spews lots of
> error
> messages to STDERR. Since the first fgets() call blocks on STDOUT, the
> whole plugin just times out and the only thing reported is from the
> SIGALRM
> saying the plugin timed out. Using a poll() or select() model instead,
> the
> plugin can capture all output from STDOUT _and_ STDERR simultaneously.
> Then
> if any timeouts happen, at least there was a chance to see some activity
> and
> take some action. Does that make sense? Let me know what you think about
> this as a model of plugin invocation.
>
> Thanks
> dave
>
>
>
>
> -----Original Message-----
> From: nagios-users-admin at lists.sourceforge.net
> [mailto:nagios-users-admin at lists.sourceforge.net]On Behalf Of Voon, Ton
> Sent: Friday, December 20, 2002 6:08 AM
> To: 'Dave Viner'; nagios-users at lists.sourceforge.net
> Subject: RE: [Nagios-users] checking memory and cpu consumption of procs
>
>
> Dave,
>
> I've tried to run your program on Solaris but I'm not having any joy. I
> managed to add in the poll checks for configure, but when running, it goes
> into an infinite loop. It seems that the line:
>
> n = poll (fdarray, 2, INFTIM);
>
> is returning 2, but the condition
>
> (fdarray[0].revents & readable)
>
> is not true and so the read_size never gets set to 0 and the loop never
> ends.
>
> I don't know if this is a Solaris limitation (uname: SunOS 2.6).
>
> Is there any particular reason you wanted to use poll? I think for a
> simple
> subcommand, the spopen and fgets used in check_procs is probably
> sufficient.
>
> Ton
>
> > -----Original Message-----
> > From: Dave Viner [SMTP:dviner at yahoo-inc.com]
> > Sent: Thursday, December 19, 2002 6:00 PM
> > To: Voon, Ton; nagios-users at lists.sourceforge.net
> > Subject: RE: [Nagios-users] checking memory and cpu consumption of
> > procs
> >
> > Here's my first stab at a check_cpu.c program. I want to use poll() to
> > watch both stdout and stderr of the child process, but I can't get it to
> > compile on both FreeBSD and Linux. FreeBSD just needs:
> > #include <poll.h>
> > but Linux needs:
> > #include <sys/poll.h>
> > #include <asm/poll.h>
> >
> > Unfortunately this means that it requires a new definition in
> > configure.in.
> > I'm not quite sure how to handle that, but I'll also look into make
> those
> > changes. Can anyone help me with that?
> >
> > Other than that, this program works very well (I think).
> >
> > thanks
> >
> > dave
> >
> > -----Original Message-----
> > From: nagios-users-admin at lists.sourceforge.net
> > [mailto:nagios-users-admin at lists.sourceforge.net]On Behalf Of Dave Viner
> > Sent: Wednesday, December 18, 2002 9:38 AM
> > To: Voon, Ton; nagios-users at lists.sourceforge.net
> > Subject: RE: [Nagios-users] checking memory and cpu consumption of procs
> >
> >
> > I'll make one for FreeBSD and Linux. I'll post it to the list when I
> have
> > it ready. Unforunately, I don't really understand autoconf/automake and
> > configure.in/makefile.am, so I don't know that I'll be able to help much
> > there....
> >
> > Thanks !
> >
> > dave
> >
> >
> > -----Original Message-----
> > From: Voon, Ton [mailto:Ton.Voon at egg.com]
> > Sent: Wednesday, December 18, 2002 1:33 AM
> > To: 'Dave Viner'; Voon, Ton; nagios-users at lists.sourceforge.net
> > Subject: RE: [Nagios-users] checking memory and cpu consumption of procs
> >
> >
> > A check_cpu, based on check_vsz, would be useful. However, it would
> > require
> > quite a few non-trivial changes to the configure.in and makefile.am to
> > pick
> > up various flags for the ps command to make it portable. If you want to
> > make
> > a start, I'd be happy to add in other OSes.
> >
> > > -----Original Message-----
> > > From: Dave Viner [SMTP:dviner at yahoo-inc.com]
> > > Sent: Tuesday, December 17, 2002 6:23 PM
> > > To: Voon, Ton; nagios-users at lists.sourceforge.net
> > > Subject: RE: [Nagios-users] checking memory and cpu consumption of
> > > procs
> > >
> > > Hi,
> > >
> > > Thanks for pointing me to check_vsz. This is a really great utility.
> > > From
> > > looking at the usage message and the code itself, it looks to me like
> > this
> > > monitors virtual memory consumption. Are there any hooks to monitor
> > %cpu
> > > consumption ? Perhaps something like
> > > ps waxco 'vsz %cpu command'
> > > ? I'm happy to try to add this in if it sounds useful.
> > >
> > > dave
> > >
> > > -----Original Message-----
> > > From: Voon, Ton [mailto:Ton.Voon at egg.com]
> > > Sent: Tuesday, December 17, 2002 1:31 AM
> > > To: 'Dave Viner'; nagios-users at lists.sourceforge.net
> > > Subject: RE: [Nagios-users] checking memory and cpu consumption of
> procs
> > >
> > >
> > > Dave,
> > >
> > > Take a look at check_vsz for the virtual size of memory usage on a
> > process
> > > level. I've put lot of functionality patches on sourceforge, so you'll
> > > need
> > > to apply those.
> > >
> > > Ton
> > >
> > > > -----Original Message-----
> > > > From: Dave Viner [SMTP:dviner at yahoo-inc.com]
> > > > Sent: Tuesday, December 17, 2002 6:56 AM
> > > > To: nagios-users at lists.sourceforge.net
> > > > Subject: [Nagios-users] checking memory and cpu consumption
> of procs
> > > >
> > > > Hi,
> > > > I want to ensure that no process on a machine consumes more
> than x %
> > > > of the
> > > > cpu, and y MB memory. Is there an existing plugin that handles
> this?
> > I
> > > > saw
> > > > that check_procs will monitor the number of processes on a machine
> > > > (including ones that match a certain name), and check_load will
> > examine
> > > > the
> > > > machine's overall load averages as reported by uptime. But I can't
> > seem
> > > > to
> > > > find anything that monitors cpu consumption or memory consumption.
> Is
> > > > there
> > > > a plugin for this already?
> > > >
> > > > thanks
> > > > dave
>
This private and confidential e-mail has been sent to you by Egg.
The Egg group of companies includes Egg Banking plc
(registered no. 2999842), Egg Financial Products Ltd (registered
no. 3319027) and Egg Investments Ltd (registered no. 3403963) which
carries out investment business on behalf of Egg and is regulated
by the Financial Services Authority.
Registered in England and Wales. Registered offices: 1 Waterhouse Square,
138-142 Holborn, London EC1N 2NA.
If you are not the intended recipient of this e-mail and have
received it in error, please notify the sender by replying with
'received in error' as the subject and then delete it from your
mailbox.
-------------------------------------------------------
This SF.NET email is sponsored by: The Best Geek Holiday Gifts!
Time is running out! Thinkgeek.com has the coolest gifts for
your favorite geek. Let your fingers do the typing. Visit Now.
T H I N K G E E K . C O M http://www.thinkgeek.com/sf/
More information about the Users
mailing list