diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 937c0ad..d1d5378 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -203,6 +203,9 @@ main (int argc, char **argv) /* Ignore self */ if (mypid == procpid) continue; + + /* Ignore child containers if we're on an OpenVZ hardware node */ + if (read_openvz_id(1) == 0 && read_openvz_id(procpid) != 0) continue; if ((options & STAT) && (strstr (statopts, procstat))) resultsum |= STAT; @@ -666,6 +669,26 @@ convert_to_seconds(char *etime) { return total; } +/* Returns the OpenVZ enviroment ID of the specified process, or -1 if we're not on OpenVZ */ +int +read_openvz_id(int procid) { + FILE *file; + char *filename = strdup(""); + char line[64]; + int result = -1; + + asprintf(&filename, "/proc/%d/status", procid); + + if ((file = fopen(filename, "r")) == NULL) return -1; + + while (fgets(line, sizeof(line), file) != NULL) { + sscanf(line, "envID:\t%d", &result); + } + + fclose(file); + return result; +} + void print_help (void)