[Nagiosplug-devel] Re: check_procs ELAPSED [patch]

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Wed Jun 1 15:51:54 CEST 2005


Sean Finney wrote:
> the whole ps format autodetection is a real mess (i was just looking at
> it last week), and should be rethought. my thinking is to remove much
> of it from the configure.in script, and instead provide a way to
> specify the options/format from the cmdline, but i probably won't be
> getting to that any time in the near future because my TODO stack is
> already nearly toppling over :)

Hey Sean,

I noticed your recent patch to check_procs.c that you committed to CVS, so I
downloaded the daily HEAD tarball and tried to build it. Unfortunately, I
encountered several syntax errors in check_procs.c as a result of your
changes when I tried to compile it using gcc 2.95.3. I presume it compiles
fine using newer versions of gcc, but I think it's a good idea to maintain
compatibility with older gcc's. In that spirit, I propose the following the
patch to check_procs.c:

--- check_procs.c_HEAD       Tue May 24 20:43:20 2005
+++ check_procs.c            Wed Jun  1 18:34:54 2005
@@ -94,7 +94,7 @@
        int procseconds = 0;
        float procpcpu = 0;
        char procstat[8];
-       char procetime[MAX_INPUT_BUFFER];
+       char procetime[MAX_INPUT_BUFFER] = { '\0' };
        char *procargs;
        char *temp_string;
 
@@ -108,12 +108,10 @@
        int expected_cols = PS_COLS - 1;
        int warn = 0; /* number of processes in warn state */
        int crit = 0; /* number of processes in crit state */
-       procetime[0]='\0'; /* keep this clean because -vvv always prints it */
        int i = 0;
-
        int result = STATE_UNKNOWN;
 
-       //setlocale (LC_ALL, "");
+       /* setlocale (LC_ALL, ""); */
        bindtextdomain (PACKAGE, LOCALEDIR);
        textdomain (PACKAGE);
 
@@ -643,6 +641,9 @@
                (minutes * 60) +
                seconds;
 
+       if (verbose >= 3 && metric == METRIC_ELAPSED) {
+               printf("seconds: %d\n", total);
+       }
        return total;
 }

Sean, would you please consider committing this patch?

Note that this patch restores the display of the converted etime to the
super-verbose debug output. I found this rather useful when debugging my
ELAPSED metric checks and I think it should be retained. However, as a
compromise, I've changed the logic that it's only displayed when the ELAPSED
metric is specified. That's really the only time it's all at all useful
anyway.

Sean, just out of curiosity, could you perhaps elaborate on why you commented
out the setlocale() call? All the other Nagios plugins seem to do it. I'm
sure you had a good reason...

The only missing piece of the puzzle needed to get the ELAPSED metirc working
on my Red Hat Linux 7.3 system was adding etime to the PS_COMMAND and
tweaking the other ps-related variables in configure.in. For that, I propose
the following patch:

--- ./configure.in_HEAD      Wed Jun  1 18:01:30 2005
+++ ./configure.in           Wed Jun  1 17:53:00 2005
@@ -593,15 +593,15 @@
 AC_PATH_PROG(PATH_TO_PS,ps)
 
 AC_MSG_CHECKING(for ps syntax)
-dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo.
+dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwwo.
 dnl so test for this first...
-if ps axwo 'stat comm vsz rss user uid pid ppid args' 2>/dev/null | \
-       egrep -i ["^ *STAT +[UCOMAND]+ +VSZ +RSS +USER +UID +PID +PPID +COMMAND"] > /dev/null
+if ps axwwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \
+       egrep -i ["^ *STAT +[UCOMAND]+ +VSZ +RSS +USER +UID +PID +PPID +ELAPSED +COMMAND"] > /dev/null
 then
-       ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos]"
-       ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu comm args'"
-       ac_cv_ps_format="%s %d %d %d %d %d %f %s %n"
-       ac_cv_ps_cols=9
+       ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]"
+       ac_cv_ps_command="$PATH_TO_PS axwwo 'stat uid pid ppid vsz rss pcpu etime comm args'"
+       ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n"
+       ac_cv_ps_cols=10
        AC_MSG_RESULT([$ac_cv_ps_command])
 
 dnl For OpenBSD 3.2 & 3.3. Must come before ps -weo




More information about the Devel mailing list