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

made more paths be macros

This commit is contained in:
Helmut Grohne 2009-01-23 12:56:20 +00:00 committed by Steve Schnepp
parent 339b8f43a9
commit 611bfb0580
5 changed files with 40 additions and 26 deletions

View File

@ -2,6 +2,8 @@
#include <stdio.h>
#include "common.h"
#define ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail"
int entropy(int argc, char **argv) {
FILE *f;
int entropy;
@ -20,12 +22,12 @@ int entropy(int argc, char **argv) {
if(!strcmp(argv[1], "autoconf"))
return writeyes();
}
if(!(f=fopen("/proc/sys/kernel/random/entropy_avail", "r"))) {
fputs("cannot open /proc/sys/kernel/random/entropy_avail\n", stderr);
if(!(f=fopen(ENTROPY_AVAIL, "r"))) {
fputs("cannot open " ENTROPY_AVAIL "\n", stderr);
return 1;
}
if(1 != fscanf(f, "%d", &entropy)) {
fputs("cannot read from /proc/sys/kernel/random/entropy_avail\n", stderr);
fputs("cannot read from " ENTROPY_AVAIL "\n", stderr);
fclose(f);
return 1;
}

View File

@ -4,6 +4,8 @@
#include <ctype.h>
#include "common.h"
#define PROC_NET_SNMP "/proc/net/snmp"
int fw_packets(int argc, char **argv) {
FILE *f;
char buff[1024], *s;
@ -24,14 +26,14 @@ int fw_packets(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
if(0 == access("/proc/net/snmp", R_OK))
if(0 == access(PROC_NET_SNMP, R_OK))
return writeyes();
else
return writeno("/proc/net/snmp not readable");
return writeno(PROC_NET_SNMP " not readable");
}
}
if(!(f=fopen("/proc/net/snmp", "r"))) {
fputs("cannot open /proc/net/snmp\n", stderr);
if(!(f=fopen(PROC_NET_SNMP, "r"))) {
fputs("cannot open " PROC_NET_SNMP "\n", stderr);
return 1;
}
while(fgets(buff, 1024, f)) {
@ -55,6 +57,6 @@ int fw_packets(int argc, char **argv) {
}
}
fclose(f);
fputs("no ip line found in /proc/net/snmp\n", stderr);
fputs("no ip line found in " PROC_NET_SNMP "\n", stderr);
return 1;
}

View File

@ -3,6 +3,8 @@
#include <stdlib.h>
#include "common.h"
#define PROC_LOADAVG "/proc/loadavg"
int load(int argc, char **argv) {
FILE *f;
int warn, crit;
@ -32,12 +34,12 @@ int load(int argc, char **argv) {
if(!strcmp(argv[1], "autoconf"))
return writeyes();
}
if(!(f=fopen("/proc/loadavg", "r"))) {
fputs("cannot open /proc/loadavg\n", stderr);
if(!(f=fopen(PROC_LOADAVG, "r"))) {
fputs("cannot open " PROC_LOADAVG "\n", stderr);
return 1;
}
if(1 != fscanf(f, "%*f %f", &val)) {
fputs("cannot read from /proc/loadavg\n", stderr);
fputs("cannot read from " PROC_LOADAVG "\n", stderr);
fclose(f);
return 1;
}

View File

@ -3,18 +3,21 @@
#include <unistd.h>
#include "common.h"
#define FS_FILE_NR "/proc/sys/fs/file-nr"
int open_files(int argc, char **argv) {
FILE *f;
int alloc, freeh, avail;
if(argc > 1) {
if(!strcmp(argv[1], "config")) {
if(!(f=fopen("/proc/sys/fs/file-nr", "r"))) {
fprintf(stderr, "cannot open /proc/sys/fs/file-nr\n");
if(!(f=fopen(FS_FILE_NR, "r"))) {
fprintf(stderr, "cannot open " FS_FILE_NR "\n");
return 1;
}
if(1 != fscanf(f, "%*d %*d %d", &avail)) {
fclose(f);
fprintf(stderr, "cannot read from /proc/sys/fs/file-nr\n");
fprintf(stderr, "cannot read from " FS_FILE_NR
"\n");
return 1;
}
fclose(f);
@ -26,24 +29,27 @@ int open_files(int argc, char **argv) {
"used.label open files\n"
"used.info The number of currently open files.\n"
"max.label max open files\n"
"max.info The maximum supported number of open files. Tune by modifying /proc/sys/fs/file-max.");
printf("used.warning %d\nused.critical %d\n", (int)(avail*0.92), (int)(avail*0.98));
"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));
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
if(0 == access("/proc/sys/fs/file-nr", R_OK))
if(0 == access(FS_FILE_NR, R_OK))
return writeyes();
else
return writeno("/proc/sys/fs/file-nr not readable");
return writeno(FS_FILE_NR " not readable");
}
}
if(!(f=fopen("/proc/sys/fs/file-nr", "r"))) {
fputs("cannot open /proc/sys/fs/file-nr\n", stderr);
if(!(f=fopen(FS_FILE_NR, "r"))) {
fputs("cannot open " FS_FILE_NR "\n", stderr);
return 1;
}
if(3 != fscanf(f, "%d %d %d", &alloc, &freeh, &avail)) {
fclose(f);
fputs("cannot read from /proc/sys/fs/file-nr\n", stderr);
fputs("cannot read from " FS_FILE_NR "\n", stderr);
return 1;
}
fclose(f);

View File

@ -3,6 +3,8 @@
#include <unistd.h>
#include "common.h"
#define FS_INODE_NR "/proc/sys/fs/inode-nr"
int open_inodes(int argc, char **argv) {
FILE *f;
int nr, freen;
@ -21,19 +23,19 @@ int open_inodes(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
if(0 == access("/proc/sys/fs/inode-nr", R_OK))
if(0 == access(FS_INODE_NR, R_OK))
return writeyes();
else
return writeno("/proc/sys/fs/inode-nr not readable");
return writeno(FS_INODE_NR " not readable");
}
}
if(!(f=fopen("/proc/sys/fs/inode-nr", "r"))) {
fputs("cannot open /proc/sys/fs/inode-nr\n", stderr);
if(!(f=fopen(FS_INODE_NR, "r"))) {
fputs("cannot open " FS_INODE_NR "\n", stderr);
return 1;
}
if(2 != fscanf(f, "%d %d", &nr, &freen)) {
fclose(f);
fputs("cannot read from /proc/sys/fs/inode-nr\n", stderr);
fputs("cannot read from " FS_INODE_NR "\n", stderr);
return 1;
}
fclose(f);