2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/tools/munin-plugins-busybox/open_files.c

59 lines
1.5 KiB
C
Raw Normal View History

2008-06-21 13:33:06 +02:00
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "common.h"
2009-01-23 13:56:20 +01:00
#define FS_FILE_NR "/proc/sys/fs/file-nr"
2008-06-21 13:33:06 +02:00
int open_files(int argc, char **argv) {
FILE *f;
int alloc, freeh, avail;
if(argc > 1) {
if(!strcmp(argv[1], "config")) {
2009-01-23 13:56:20 +01:00
if(!(f=fopen(FS_FILE_NR, "r"))) {
fprintf(stderr, "cannot open " FS_FILE_NR "\n");
2008-06-21 13:33:06 +02:00
return 1;
}
if(1 != fscanf(f, "%*d %*d %d", &avail)) {
fclose(f);
2009-01-23 13:56:20 +01:00
fprintf(stderr, "cannot read from " FS_FILE_NR
"\n");
2008-06-21 13:33:06 +02:00
return 1;
}
fclose(f);
puts("graph_title File table usage\n"
"graph_args --base 1000 -l 0\n"
"graph_vlabel number of open files\n"
"graph_category system\n"
"graph_info This graph monitors the Linux open files table.\n"
"used.label open files\n"
"used.info The number of currently open files.\n"
"max.label max open files\n"
2009-01-23 13:56:20 +01:00
"max.info The maximum supported number of open "
"files. Tune by modifying " FS_FILE_NR
".");
printf("used.warning %d\nused.critical %d\n",
(int)(avail*0.92), (int)(avail*0.98));
2008-06-21 13:33:06 +02:00
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
2009-01-23 13:56:20 +01:00
if(0 == access(FS_FILE_NR, R_OK))
2008-06-21 13:33:06 +02:00
return writeyes();
else
2009-01-23 13:56:20 +01:00
return writeno(FS_FILE_NR " not readable");
2008-06-21 13:33:06 +02:00
}
}
2009-01-23 13:56:20 +01:00
if(!(f=fopen(FS_FILE_NR, "r"))) {
fputs("cannot open " FS_FILE_NR "\n", stderr);
2008-06-21 13:33:06 +02:00
return 1;
}
if(3 != fscanf(f, "%d %d %d", &alloc, &freeh, &avail)) {
fclose(f);
2009-01-23 13:56:20 +01:00
fputs("cannot read from " FS_FILE_NR "\n", stderr);
2008-06-21 13:33:06 +02:00
return 1;
}
fclose(f);
printf("used.value %d\nmax.value %d\n", alloc-freeh, avail);
return 0;
}