From 209937078bc6934159706dcd73239a850bdfcf7f Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 21 Jun 2008 11:33:06 +0000 Subject: [PATCH 01/11] initial tree --- tools/munin-plugins-busybox/Makefile | 16 +++ tools/munin-plugins-busybox/common.c | 14 ++ tools/munin-plugins-busybox/common.h | 7 + tools/munin-plugins-busybox/cpu.c | 157 ++++++++++++++++++++++ tools/munin-plugins-busybox/entropy.c | 35 +++++ tools/munin-plugins-busybox/forks.c | 44 ++++++ tools/munin-plugins-busybox/fw_packets.c | 60 +++++++++ tools/munin-plugins-busybox/interrupts.c | 47 +++++++ tools/munin-plugins-busybox/load.c | 47 +++++++ tools/munin-plugins-busybox/main.c | 64 +++++++++ tools/munin-plugins-busybox/open_files.c | 52 +++++++ tools/munin-plugins-busybox/open_inodes.c | 42 ++++++ tools/munin-plugins-busybox/processes.c | 42 ++++++ tools/munin-plugins-busybox/swap.c | 78 +++++++++++ tools/munin-plugins-busybox/uptime.c | 32 +++++ 15 files changed, 737 insertions(+) create mode 100644 tools/munin-plugins-busybox/Makefile create mode 100644 tools/munin-plugins-busybox/common.c create mode 100644 tools/munin-plugins-busybox/common.h create mode 100644 tools/munin-plugins-busybox/cpu.c create mode 100644 tools/munin-plugins-busybox/entropy.c create mode 100644 tools/munin-plugins-busybox/forks.c create mode 100644 tools/munin-plugins-busybox/fw_packets.c create mode 100644 tools/munin-plugins-busybox/interrupts.c create mode 100644 tools/munin-plugins-busybox/load.c create mode 100644 tools/munin-plugins-busybox/main.c create mode 100644 tools/munin-plugins-busybox/open_files.c create mode 100644 tools/munin-plugins-busybox/open_inodes.c create mode 100644 tools/munin-plugins-busybox/processes.c create mode 100644 tools/munin-plugins-busybox/swap.c create mode 100644 tools/munin-plugins-busybox/uptime.c diff --git a/tools/munin-plugins-busybox/Makefile b/tools/munin-plugins-busybox/Makefile new file mode 100644 index 00000000..56a56f63 --- /dev/null +++ b/tools/munin-plugins-busybox/Makefile @@ -0,0 +1,16 @@ +CC=gcc +CFLAGS=-W -Wall -pedantic -Wextra -g -O2 +OBJS=main.o common.o cpu.o entropy.o forks.o fw_packets.o interrupts.o load.o \ + open_files.o open_inodes.o processes.o swap.o uptime.o +LINKS=cpu entropy forks fw_packets interrupts load open_files open_inodes \ + processes swap uptime + +%.o:%.c + ${CC} ${CFLAGS} -c $< -o $@ +all:main + for l in ${LINKS}; do test -f $$l || ln -s main $$l; done +main:${OBJS} + ${CC} ${CFLAGS} $^ -o $@ +clean: + rm -f main ${OBJS} ${LINKS} +.PHONY:all clean diff --git a/tools/munin-plugins-busybox/common.c b/tools/munin-plugins-busybox/common.c new file mode 100644 index 00000000..3d78e518 --- /dev/null +++ b/tools/munin-plugins-busybox/common.c @@ -0,0 +1,14 @@ +#include + +int writeyes(void) { + puts("yes"); + return 0; +} + +int writeno(const char *s) { + if(s) + printf("no (%s)\n", s); + else + puts("no"); + return 1; +} diff --git a/tools/munin-plugins-busybox/common.h b/tools/munin-plugins-busybox/common.h new file mode 100644 index 00000000..67a5bebc --- /dev/null +++ b/tools/munin-plugins-busybox/common.h @@ -0,0 +1,7 @@ +#ifndef COMMON_H +#define COMMON_H + +int writeyes(void); +int writeno(const char *); + +#endif diff --git a/tools/munin-plugins-busybox/cpu.c b/tools/munin-plugins-busybox/cpu.c new file mode 100644 index 00000000..171a3d3c --- /dev/null +++ b/tools/munin-plugins-busybox/cpu.c @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include +#include "common.h" + +#define SYSWARNING 30 +#define SYSCRITICAL 50 +#define USRWARNING 80 + +int cpu(int argc, char **argv) { + FILE *f; + char buff[256], *s; + int ncpu=0, extinfo=0, scaleto100=0; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + s = getenv("scaleto100"); + if(s && !strcmp(s, "yes")) + scaleto100=1; + + if(!(f=fopen("/proc/stat", "r"))) { + fputs("cannot open /proc/stat\n", stderr); + return 1; + } + while(fgets(buff, 256, f)) { + if(!strncmp(buff, "cpu", 3)) { + if(isdigit(buff[3])) + ncpu++; + if(buff[3] == ' ') { + s = strtok(buff+4, " \t"); + for(extinfo=0;strtok(NULL, " \t");extinfo++) + ; + } + } + } + fclose(f); + + if(ncpu < 1 || extinfo < 4) { + fputs("cannot parse /proc/stat\n", stderr); + return 1; + } + + puts("graph_title CPU usage"); + if(extinfo == 7) + puts("graph_order system user nice idle iowait irq softirq"); + else + puts("graph_order system user nice idle"); + if(scaleto100) + puts("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100"); + else + printf("graph_args --base 1000 -r --lower-limit 0 --upper-limit %d\n", 100 * ncpu); + puts("graph_vlabel %\n" + "graph_scale no\n" + "graph_info This graph shows how CPU time is spent.\n" + "graph_category system\n" + "graph_period second\n" + "system.label system\n" + "system.draw AREA"); + printf("system.max %d\n", 100 * ncpu); + puts("system.min 0\n" + "system.type DERIVE"); + printf("system.warning %d\n", SYSWARNING * ncpu); + printf("system.critical %d\n", SYSCRITICAL * ncpu); + puts("system.info CPU time spent by the kernel in system activities\n" + "user.label user\n" + "user.draw STACK\n" + "user.min 0"); + printf("user.max %d\n", 100 * ncpu); + printf("user.warning %d\n", USRWARNING * ncpu); + puts("user.type DERIVE\n" + "user.info CPU time spent by normal programs and daemons\n" + "nice.label nice\n" + "nice.draw STACK\n" + "nice.min 0"); + printf("nice.max %d\n", 100 * ncpu); + puts("nice.type DERIVE\n" + "nice.info CPU time spent by nice(1)d programs\n" + "idle.label idle\n" + "idle.draw STACK\n" + "idle.min 0"); + printf("idle.max %d\n", 100 * ncpu); + puts("idle.type DERIVE\n" + "idle.info Idle CPU time"); + if(scaleto100) + printf("system.cdef system,%d,/\n" + "user.cdef user,%d,/\n" + "nice.cdef nice,%d,/\n" + "idle.cdef idle,%d,/\n", ncpu, ncpu, ncpu, ncpu); + if(extinfo == 7) { + puts("iowait.label iowait\n" + "iowait.draw STACK\n" + "iowait.min 0"); + printf("iowait.max %d\n", 100 * ncpu); + puts("iowait.type DERIVE\n" + "iowait.info CPU time spent waiting for I/O operations to finish\n" + "irq.label irq\n" + "irq.draw STACK\n" + "irq.min 0"); + printf("irq.max %d\n", 100 * ncpu); + puts("irq.type DERIVE\n" + "irq.info CPU time spent handling interrupts\n" + "softirq.label softirq\n" + "softirq.draw STACK\n" + "softirq.min 0"); + printf("softirq.max %d\n", 100 * ncpu); + puts("softirq.type DERIVE\n" + "softirq.info CPU time spent handling \"batched\" interrupts"); + if(scaleto100) + printf("iowait.cdef iowait,%d,/\n" + "irq.cdef irq,%d,/\n" + "softirq.cdef softirq,%d,/\n", ncpu, ncpu, ncpu); + } + return 0; + } + if(!strcmp(argv[1], "autoconf")) { + if(0 == access("/proc/stat", R_OK)) + return writeyes(); + else + return writeno("/proc/stat not readable"); + } + } + if(!(f=fopen("/proc/stat", "r"))) { + fputs("cannot open /proc/stat\n", stderr); + return 1; + } + while(fgets(buff, 256, f)) { + if(!strncmp(buff, "cpu ", 4)) { + fclose(f); + if(!(s = strtok(buff+4, " \t"))) + break; + printf("user.value %s\n", s); + if(!(s = strtok(NULL, " \t"))) + break; + printf("nice.value %s\n", s); + if(!(s = strtok(NULL, " \t"))) + break; + printf("system.value %s\n", s); + if(!(s = strtok(NULL, " \t"))) + break; + printf("idle.value %s\n", s); + if(!(s = strtok(NULL, " \t"))) + return 0; + printf("iowait.value %s\n", s); + if(!(s = strtok(NULL, " \t"))) + return 0; + printf("irq.value %s\n", s); + if(!(s = strtok(NULL, " \t"))) + return 0; + printf("softirq.value %s\n", s); + return 0; + } + } + fclose(f); + fputs("no cpu line found in /proc/stat\n", stderr); + return 1; +} diff --git a/tools/munin-plugins-busybox/entropy.c b/tools/munin-plugins-busybox/entropy.c new file mode 100644 index 00000000..4a5d8468 --- /dev/null +++ b/tools/munin-plugins-busybox/entropy.c @@ -0,0 +1,35 @@ +#include +#include +#include "common.h" + +int entropy(int argc, char **argv) { + FILE *f; + int entropy; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Available entropy\n" + "graph_args --base 1000 -l 0\n" + "graph_vlabel entropy (bytes)\n" + "graph_scale no\n" + "graph_category system\n" + "graph_info This graph shows the amount of entropy available in the system.\n" + "entropy.label entropy\n" + "entropy.info The number of random bytes available. This is typically used by cryptographic applications."); + return 0; + } + 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); + return 1; + } + if(1 != fscanf(f, "%d", &entropy)) { + fputs("cannot read from /proc/sys/kernel/random/entropy_avail\n", stderr); + fclose(f); + return 1; + } + fclose(f); + printf("entropy.value %d\n", entropy); + return 0; +} diff --git a/tools/munin-plugins-busybox/forks.c b/tools/munin-plugins-busybox/forks.c new file mode 100644 index 00000000..fa4dadb4 --- /dev/null +++ b/tools/munin-plugins-busybox/forks.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include "common.h" + +int forks(int argc, char **argv) { + FILE *f; + char buff[256]; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Fork rate\n" + "graph_args --base 1000 -l 0 \n" + "graph_vlabel forks / ${graph_period}\n" + "graph_category processes\n" + "graph_info This graph shows the forking rate (new processes started).\n" + "forks.label forks\n" + "forks.type DERIVE\n" + "forks.min 0\n" + "forks.max 100000\n" + "forks.info The number of forks per second."); + return 0; + } + if(!strcmp(argv[1], "autoconf")) { + if(0 == access("/proc/stat", R_OK)) + return writeyes(); + else + return writeno("/proc/stat not readable"); + } + } + if(!(f=fopen("/proc/stat", "r"))) { + fputs("cannot open /proc/stat\n", stderr); + return 1; + } + while(fgets(buff, 256, f)) { + if(!strncmp(buff, "processes ", 10)) { + fclose(f); + printf("forks.value %s", buff+10); + return 0; + } + } + fclose(f); + fputs("no processes line found in /proc/stat\n", stderr); + return 1; +} diff --git a/tools/munin-plugins-busybox/fw_packets.c b/tools/munin-plugins-busybox/fw_packets.c new file mode 100644 index 00000000..06367dde --- /dev/null +++ b/tools/munin-plugins-busybox/fw_packets.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include "common.h" + +int fw_packets(int argc, char **argv) { + FILE *f; + char buff[1024], *s; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Firewall Throughput\n" + "graph_args --base 1000 -l 0\n" + "graph_vlabel Packets/${graph_period}\n" + "graph_category network\n" + "received.label Received\n" + "received.draw AREA\n" + "received.type DERIVE\n" + "received.min 0\n" + "forwarded.label Forwarded\n" + "forwarded.draw LINE2\n" + "forwarded.type DERIVE\n" + "forwarded.min 0"); + return 0; + } + if(!strcmp(argv[1], "autoconf")) { + if(0 == access("/proc/net/snmp", R_OK)) + return writeyes(); + else + return writeno("/proc/net/snmp not readable"); + } + } + if(!(f=fopen("/proc/net/snmp", "r"))) { + fputs("cannot open /proc/net/snmp\n", stderr); + return 1; + } + while(fgets(buff, 1024, f)) { + if(!strncmp(buff, "Ip: ", 4) && isdigit(buff[4])) { + fclose(f); + if(!(s = strtok(buff+4, " \t"))) + break; + if(!(s = strtok(NULL, " \t"))) + break; + if(!(s = strtok(NULL, " \t"))) + break; + printf("received.value %s\n", s); + if(!(s = strtok(NULL, " \t"))) + break; + if(!(s = strtok(NULL, " \t"))) + break; + if(!(s = strtok(NULL, " \t"))) + break; + printf("forwarded.value %s\n", s); + return 0; + } + } + fclose(f); + fputs("no ip line found in /proc/net/snmp\n", stderr); + return 1; +} diff --git a/tools/munin-plugins-busybox/interrupts.c b/tools/munin-plugins-busybox/interrupts.c new file mode 100644 index 00000000..2755ccf6 --- /dev/null +++ b/tools/munin-plugins-busybox/interrupts.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include "common.h" + +int interrupts(int argc, char **argv) { + FILE *f; + char buff[256]; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Interrupts & context switches\n" + "graph_args --base 1000 -l 0\n" + "graph_vlabel interrupts & ctx switches / ${graph_period}\n" + "graph_category system\n" + "graph_info This graph shows the number of interrupts and context switches on the system. These are typically high on a busy system.\n" + "intr.info Interrupts are events that alter sequence of instructions executed by a processor. They can come from either hardware (exceptions, NMI, IRQ) or software."); + puts("ctx.info A context switch occurs when a multitasking operatings system suspends the currently running process, and starts executing another.\n" + "intr.label interrupts\n" + "ctx.label context switches\n" + "intr.type DERIVE\n" + "ctx.type DERIVE\n" + "intr.max 100000\n" + "ctx.max 100000\n" + "intr.min 0\n" + "ctx.min 0"); + return 0; + } + if(!strcmp(argv[1], "autoconf")) { + if(0 == access("/proc/stat", R_OK)) + return writeyes(); + else + return writeno("/proc/stat not readable"); + } + } + if(!(f=fopen("/proc/stat", "r"))) { + fputs("cannot open /proc/stat\n", stderr); + return 1; + } + while(fgets(buff, 256, f)) { + if(!strncmp(buff, "intr ", 5)) + printf("intr.value %s", buff+5); + else if(!strncmp(buff, "ctxt ", 5)) + printf("ctx.value %s", buff+5); + } + fclose(f); + return 0; +} diff --git a/tools/munin-plugins-busybox/load.c b/tools/munin-plugins-busybox/load.c new file mode 100644 index 00000000..c894f5e2 --- /dev/null +++ b/tools/munin-plugins-busybox/load.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include "common.h" + +int load(int argc, char **argv) { + FILE *f; + int warn, crit; + float val; + char *s; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + s = getenv("load_warn"); + if(s) + warn = atoi(s); + else + warn = 10; + s = getenv("load_crit"); + if(s) + crit = atoi(s); + else + crit = 120; + puts("graph_title Load average\n" + "graph_args --base 1000 -l 0\n" + "graph_vlabel load\n" + "graph_scale no\n" + "graph_category system\n" + "load.label load"); + printf("load.warning %d\nload.critical %d\n", warn, crit); + return 0; + } + if(!strcmp(argv[1], "autoconf")) + return writeyes(); + } + 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); + fclose(f); + return 1; + } + fclose(f); + printf("load.value %.2f\n", val); + return 0; +} diff --git a/tools/munin-plugins-busybox/main.c b/tools/munin-plugins-busybox/main.c new file mode 100644 index 00000000..348b4f65 --- /dev/null +++ b/tools/munin-plugins-busybox/main.c @@ -0,0 +1,64 @@ +#include +#include +#include + +int cpu(int argc, char **argv); +int entropy(int argc, char **argv); +int forks(int argc, char **argv); +int fw_packets(int argc, char **argv); +int interrupts(int argc, char **argv); +int load(int argc, char **argv); +int open_files(int argc, char **argv); +int open_inodes(int argc, char **argv); +int processes(int argc, char **argv); +int swap(int argc, char **argv); +int uptime(int argc, char **argv); + +int main(int argc, char **argv) { + char *progname; + progname = basename(argv[0]); + switch(*progname) { + case 'c': + if(!strcmp(progname+1, "pu")) + return cpu(argc, argv); + break; + case 'e': + if(!strcmp(progname+1, "ntropy")) + return entropy(argc, argv); + break; + case 'f': + if(!strcmp(progname+1, "orks")) + return forks(argc, argv); + if(!strcmp(progname+1, "w_packets")) + return fw_packets(argc, argv); + break; + case 'i': + if(!strcmp(progname+1, "nterrupts")) + return interrupts(argc, argv); + break; + case 'l': + if(!strcmp(progname+1, "oad")) + return load(argc, argv); + break; + case 'o': + if(!strcmp(progname+1, "pen_files")) + return open_files(argc, argv); + if(!strcmp(progname+1, "pen_inodes")) + return open_inodes(argc, argv); + break; + case 'p': + if(!strcmp(progname+1, "rocesses")) + return processes(argc, argv); + break; + case 's': + if(!strcmp(progname+1, "wap")) + return swap(argc, argv); + break; + case 'u': + if(!strcmp(progname+1, "ptime")) + return uptime(argc, argv); + break; + } + fprintf(stderr, "function not specified\n"); + return 1; +} diff --git a/tools/munin-plugins-busybox/open_files.c b/tools/munin-plugins-busybox/open_files.c new file mode 100644 index 00000000..3f82c8b5 --- /dev/null +++ b/tools/munin-plugins-busybox/open_files.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include "common.h" + +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"); + return 1; + } + if(1 != fscanf(f, "%*d %*d %d", &avail)) { + fclose(f); + fprintf(stderr, "cannot read from /proc/sys/fs/file-nr\n"); + 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" + "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)); + return 0; + } + if(!strcmp(argv[1], "autoconf")) { + if(0 == access("/proc/sys/fs/file-nr", R_OK)) + return writeyes(); + else + return writeno("/proc/sys/fs/file-nr not readable"); + } + } + if(!(f=fopen("/proc/sys/fs/file-nr", "r"))) { + fputs("cannot open /proc/sys/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); + return 1; + } + fclose(f); + printf("used.value %d\nmax.value %d\n", alloc-freeh, avail); + return 0; +} diff --git a/tools/munin-plugins-busybox/open_inodes.c b/tools/munin-plugins-busybox/open_inodes.c new file mode 100644 index 00000000..bc20cc60 --- /dev/null +++ b/tools/munin-plugins-busybox/open_inodes.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include "common.h" + +int open_inodes(int argc, char **argv) { + FILE *f; + int nr, freen; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Inode table usage\n" + "graph_args --base 1000 -l 0\n" + "graph_vlabel number of open inodes\n" + "graph_category system\n" + "graph_info This graph monitors the Linux open inode table.\n" + "used.label open inodes\n" + "used.info The number of currently open inodes.\n" + "max.label inode table size\n" + "max.info The size of the system inode table. This is dynamically adjusted by the kernel."); + + return 0; + } + if(!strcmp(argv[1], "autoconf")) { + if(0 == access("/proc/sys/fs/inode-nr", R_OK)) + return writeyes(); + else + return writeno("/proc/sys/fs/inode-nr not readable"); + } + } + if(!(f=fopen("/proc/sys/fs/inode-nr", "r"))) { + fputs("cannot open /proc/sys/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); + return 1; + } + fclose(f); + printf("used.value %d\nmax.value %d\n", nr-freen, nr); + return 0; +} diff --git a/tools/munin-plugins-busybox/processes.c b/tools/munin-plugins-busybox/processes.c new file mode 100644 index 00000000..b5227686 --- /dev/null +++ b/tools/munin-plugins-busybox/processes.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include "common.h" + +int processes(int argc, char **argv) { + DIR *d; + struct dirent *e; + char *s; + int n=0; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Number of Processes\n" + "graph_args --base 1000 -l 0 \n" + "graph_vlabel number of processes\n" + "graph_category processes\n" + "graph_info This graph shows the number of processes in the system.\n" + "processes.label processes\n" + "processes.draw LINE2\n" + "processes.info The current number of processes."); + return 0; + } + if(!strcmp(argv[1], "autoconf")) + return writeyes(); + } + if(!(d = opendir("/proc"))) { + fputs("cannot open /proc\n", stderr); + return 1; + } + while((e = readdir(d))) { + for(s=e->d_name;*s;++s) + if(!isdigit(*s)) + break; + if(!*s) + ++n; + } + closedir(d); + printf("processes.value %d\n", n); + return 0; +} diff --git a/tools/munin-plugins-busybox/swap.c b/tools/munin-plugins-busybox/swap.c new file mode 100644 index 00000000..fef6cc32 --- /dev/null +++ b/tools/munin-plugins-busybox/swap.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include "common.h" + +int swap(int argc, char **argv) { + FILE *f; + char buff[256]; + int in, out; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Swap in/out\n" + "graph_args -l 0 --base 1000\n" + "graph_vlabel pages per ${graph_period} in (-) / out (+)\n" + "graph_category system\n" + "swap_in.label swap\n" + "swap_in.type DERIVE\n" + "swap_in.max 100000\n" + "swap_in.min 0\n" + "swap_in.graph no\n" + "swap_out.label swap\n" + "swap_out.type DERIVE\n" + "swap_out.max 100000\n" + "swap_out.min 0\n" + "swap_out.negative swap_in"); + + return 0; + } + if(!strcmp(argv[1], "autoconf")) { + if(0 == access("/proc/stat", R_OK)) + return writeyes(); + else + return writeno("/proc/stat not readable"); + } + } + if(!access("/proc/vmstat", F_OK)) { + in=out=0; + if(!(f=fopen("/proc/vmstat", "r"))) { + fputs("cannot open /proc/vmstat\n", stderr); + return 1; + } + while(fgets(buff, 256, f)) { + if(!in && !strncmp(buff, "pswpin ", 7)) { + ++in; + printf("swap_in.value %s", buff+7); + } + else if(!out && !strncmp(buff, "pswpout ", 8)) { + ++out; + printf("swap_out.value %s", buff+8); + } + } + fclose(f); + if(!in*out) { + fputs("no usable data on /proc/vmstat\n", stderr); + return 1; + } + return 0; + } else { + if(!(f=fopen("/proc/stat", "r"))) { + fputs("cannot open /proc/stat\n", stderr); + return 1; + } + while(fgets(buff, 256, f)) { + if(!strncmp(buff, "swap ", 5)) { + fclose(f); + if(2 != sscanf(buff+5, "%d %d", &in, &out)) { + fputs("bad data on /proc/stat\n", stderr); + return 1; + } + printf("swap_in.value %d\nswap_out.value %d\n", in, out); + return 0; + } + } + fclose(f); + fputs("no swap line found in /proc/stat\n", stderr); + return 1; + } +} diff --git a/tools/munin-plugins-busybox/uptime.c b/tools/munin-plugins-busybox/uptime.c new file mode 100644 index 00000000..ce6093fa --- /dev/null +++ b/tools/munin-plugins-busybox/uptime.c @@ -0,0 +1,32 @@ +#include +#include +#include "common.h" + +int uptime(int argc, char **argv) { + FILE *f; + float uptime; + if(argc > 1) { + if(!strcmp(argv[1], "config")) { + puts("graph_title Uptime\n" + "graph_args --base 1000 -l 0 \n" + "graph_vlabel uptime in days\n" + "uptime.label uptime\n" + "uptime.draw AREA"); + return 0; + } + if(!strcmp(argv[1], "autoconf")) + return writeyes(); + } + if(!(f=fopen("/proc/uptime", "r"))) { + fputs("cannot open /proc/uptime\n", stderr); + return 1; + } + if(1 != fscanf(f, "%f", &uptime)) { + fputs("cannot read from /proc/uptime\n", stderr); + fclose(f); + return 1; + } + fclose(f); + printf("uptime.value %.2f\n", uptime/86400); + return 0; +} From bede1947b2025035b6d7a4a7c6c54e15d92e6d08 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 21 Jun 2008 11:45:12 +0000 Subject: [PATCH 02/11] change name to munin-plugins-busybox --- tools/munin-plugins-busybox/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/munin-plugins-busybox/Makefile b/tools/munin-plugins-busybox/Makefile index 56a56f63..34d9c491 100644 --- a/tools/munin-plugins-busybox/Makefile +++ b/tools/munin-plugins-busybox/Makefile @@ -7,10 +7,10 @@ LINKS=cpu entropy forks fw_packets interrupts load open_files open_inodes \ %.o:%.c ${CC} ${CFLAGS} -c $< -o $@ -all:main - for l in ${LINKS}; do test -f $$l || ln -s main $$l; done -main:${OBJS} +all:munin-plugins-busybox + for l in ${LINKS}; do test -f $$l || ln -s munin-plugins-busybox $$l; done +munin-plugins-busybox:${OBJS} ${CC} ${CFLAGS} $^ -o $@ clean: - rm -f main ${OBJS} ${LINKS} + rm -f munin-plugins-busybox ${OBJS} ${LINKS} .PHONY:all clean From 2f167d679fb1565a52d90c501983ba4bd710ddf7 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 21 Jun 2008 11:52:14 +0000 Subject: [PATCH 03/11] fix bug in swap.c --- tools/munin-plugins-busybox/swap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/munin-plugins-busybox/swap.c b/tools/munin-plugins-busybox/swap.c index fef6cc32..1a270fe8 100644 --- a/tools/munin-plugins-busybox/swap.c +++ b/tools/munin-plugins-busybox/swap.c @@ -50,7 +50,7 @@ int swap(int argc, char **argv) { } } fclose(f); - if(!in*out) { + if(!(in*out)) { fputs("no usable data on /proc/vmstat\n", stderr); return 1; } From 881a6374f5f9e37a65bada9cb5cbe022826522fc Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 21 Jun 2008 11:52:29 +0000 Subject: [PATCH 04/11] strip the binary --- tools/munin-plugins-busybox/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/munin-plugins-busybox/Makefile b/tools/munin-plugins-busybox/Makefile index 34d9c491..dae1b6c7 100644 --- a/tools/munin-plugins-busybox/Makefile +++ b/tools/munin-plugins-busybox/Makefile @@ -8,6 +8,7 @@ LINKS=cpu entropy forks fw_packets interrupts load open_files open_inodes \ %.o:%.c ${CC} ${CFLAGS} -c $< -o $@ all:munin-plugins-busybox + strip -s munin-plugins-busybox for l in ${LINKS}; do test -f $$l || ln -s munin-plugins-busybox $$l; done munin-plugins-busybox:${OBJS} ${CC} ${CFLAGS} $^ -o $@ From ad5c0c537a1a204721cbf3de8122e1d32b1ddd32 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 21 Jun 2008 11:52:41 +0000 Subject: [PATCH 05/11] added a README --- tools/munin-plugins-busybox/README | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tools/munin-plugins-busybox/README diff --git a/tools/munin-plugins-busybox/README b/tools/munin-plugins-busybox/README new file mode 100644 index 00000000..2945e709 --- /dev/null +++ b/tools/munin-plugins-busybox/README @@ -0,0 +1,30 @@ +What is this? +~~~~~~~~~~~~~ +This is a rewrite of commonly used plugins in C as a single binary. The +purpose is reducing resource usage: + * disk space: the binary is smaler than the plugins together + * more diskspace: it has no dependencies on other programs + * less forks: it does not fork internally + * faster startup: it doesn't start perl or shell + * less memory: just a small C program + * less file accesses: one binary for many plugins +This can be useful for machines with restricted resources like embedded +machines. + +What plugins are included? +~~~~~~~~~~~~~~~~~~~~~~~~~~ +cpu entropy forks fw_packets interrupts load open_files open_inodes +processes swap uptime + +How to use? +~~~~~~~~~~~ +After compiling there will be binary munin-plugins-busybox. You can just +replace symlinks in /etc/munin/plugins/ with symlinks to this binary. + +License? +~~~~~~~~ +(C) 2008 Helmut Grohne +GPLv3 applies to *.c *.h and Makefile + +# vim7:spelllang=en +# vim:textwidth=75 From 1adee557369190c0da15183c61a91a8167734107 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 21 Jun 2008 12:18:23 +0000 Subject: [PATCH 06/11] it was not really clear to be about munin --- tools/munin-plugins-busybox/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/munin-plugins-busybox/README b/tools/munin-plugins-busybox/README index 2945e709..4d8df262 100644 --- a/tools/munin-plugins-busybox/README +++ b/tools/munin-plugins-busybox/README @@ -1,7 +1,7 @@ What is this? ~~~~~~~~~~~~~ -This is a rewrite of commonly used plugins in C as a single binary. The -purpose is reducing resource usage: +This is a rewrite of commonly used munin plugins in C as a single binary. +The purpose is reducing resource usage: * disk space: the binary is smaler than the plugins together * more diskspace: it has no dependencies on other programs * less forks: it does not fork internally From a61fdfd103a15f3d747c7fbc94bb8737e037bbd6 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 21 Jun 2008 12:18:50 +0000 Subject: [PATCH 07/11] readme -> disadvantages? --- tools/munin-plugins-busybox/README | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/munin-plugins-busybox/README b/tools/munin-plugins-busybox/README index 4d8df262..3e1457e0 100644 --- a/tools/munin-plugins-busybox/README +++ b/tools/munin-plugins-busybox/README @@ -16,6 +16,12 @@ What plugins are included? cpu entropy forks fw_packets interrupts load open_files open_inodes processes swap uptime +Disadvantages? +~~~~~~~~~~~~~~ +You lose flexibility. You can no longer just edit the plugin and if you try +you have to be very careful not to break it. If you want to deploy this you +have to create one binary for each architecture. + How to use? ~~~~~~~~~~~ After compiling there will be binary munin-plugins-busybox. You can just From bdf2dd257a054848948ea0136db01f79ce97714a Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 22 Jan 2009 14:30:31 +0000 Subject: [PATCH 08/11] added if_err_ plugin --- tools/munin-plugins-busybox/Makefile | 8 +- tools/munin-plugins-busybox/if_err_.c | 123 ++++++++++++++++++++++++++ tools/munin-plugins-busybox/main.c | 3 + 3 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 tools/munin-plugins-busybox/if_err_.c diff --git a/tools/munin-plugins-busybox/Makefile b/tools/munin-plugins-busybox/Makefile index dae1b6c7..fe465f64 100644 --- a/tools/munin-plugins-busybox/Makefile +++ b/tools/munin-plugins-busybox/Makefile @@ -1,9 +1,9 @@ CC=gcc CFLAGS=-W -Wall -pedantic -Wextra -g -O2 -OBJS=main.o common.o cpu.o entropy.o forks.o fw_packets.o interrupts.o load.o \ - open_files.o open_inodes.o processes.o swap.o uptime.o -LINKS=cpu entropy forks fw_packets interrupts load open_files open_inodes \ - processes swap uptime +OBJS=main.o common.o cpu.o entropy.o forks.o fw_packets.o interrupts.o \ + if_err_.o load.o open_files.o open_inodes.o processes.o swap.o uptime.o +LINKS=cpu entropy forks fw_packets interrupts if_err_eth0 load open_files \ + open_inodes processes swap uptime %.o:%.c ${CC} ${CFLAGS} -c $< -o $@ diff --git a/tools/munin-plugins-busybox/if_err_.c b/tools/munin-plugins-busybox/if_err_.c new file mode 100644 index 00000000..caee6b3a --- /dev/null +++ b/tools/munin-plugins-busybox/if_err_.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include + +#define PROC_NET_DEV "/proc/net/dev" + +int if_err_(int argc, char **argv) { + char *interface; + FILE *f; + char buff[256], *s; + int i; + + interface = basename(argv[0]); + if(strncmp(interface, "if_err_", 7) != 0) { + fputs("if_err_ invoked with invalid basename\n", stderr); + return 1; + } + interface += 7; + + if(argc > 1) { + if(!strcmp(argv[1], "autoconf")) { + if(access(PROC_NET_DEV, R_OK) == 0) { + puts("yes"); + return 0; + } else { + puts("no (/proc/net/dev not found)"); + return 1; + } + } + if(!strcmp(argv[1], "suggest")) { + if(NULL == (f = fopen(PROC_NET_DEV, "r"))) + return 1; + while(fgets(buff, 256, f)) { + for(s=buff;*s == ' ';++s) + ; + i = 0; + if(!strncmp(s, "eth", 3)) + i = 3; + else if(!strncmp(s, "wlan", 4)) + i = 4; + else if(!strncmp(s, "ath", 3)) + i = 3; + else if(!strncmp(s, "ra", 2)) + i = 2; + if(i == 0) + continue; + while(isdigit(s[i])) + ++i; + if(s[i] != ':') + continue; + s[i] = '\0'; + puts(s); + } + fclose(f); + return 0; + } + if(!strcmp(argv[1], "config")) { + puts("graph_order rcvd trans"); + printf("graph_title %s errors\n", interface); + puts("graph_args --base 1000\n" + "graph_vlabel packets in (-) / out (+) per " + "${graph_period}\n" + "graph_category network"); + printf("graph_info This graph shows the amount of " + "errors on the %s network interface.\n", + interface); + puts("rcvd.label packets\n" + "rcvd.type COUNTER\n" + "rcvd.graph no\n" + "rcvd.warning 1\n" + "trans.label packets\n" + "trans.type COUNTER\n" + "trans.negative rcvd\n" + "trans.warning 1"); + return 0; + } + } + if(NULL == (f = fopen(PROC_NET_DEV, "r"))) + return 1; + while(fgets(buff, 256, f)) { + for(s=buff;*s == ' ';++s) + ; + if(0 != strncmp(s, interface, strlen(interface))) + continue; + s += strlen(interface); + if(*s != ':') + continue; + ++s; + + while(*s == ' ') + ++s; + + for(i=1;i<3;++i) { + while(isdigit(*s)) + ++s; + while(isspace(*s)) + ++s; + } + for(i=0;isdigit(s[i]);++i) + ; + printf("rcvd.value "); + fwrite(s, 1, i, stdout); + putchar('\n'); + s += i; + while(isspace(*s)) + ++s; + + for(i=4;i<11;++i) { + while(isdigit(*s)) + ++s; + while(isspace(*s)) + ++s; + } + for(i=0;isdigit(s[i]);++i) + ; + printf("trans.value "); + fwrite(s, 1, i, stdout); + putchar('\n'); + } + return 0; +} diff --git a/tools/munin-plugins-busybox/main.c b/tools/munin-plugins-busybox/main.c index 348b4f65..b1833a04 100644 --- a/tools/munin-plugins-busybox/main.c +++ b/tools/munin-plugins-busybox/main.c @@ -6,6 +6,7 @@ int cpu(int argc, char **argv); int entropy(int argc, char **argv); int forks(int argc, char **argv); int fw_packets(int argc, char **argv); +int if_err_(int argc, char **argv); int interrupts(int argc, char **argv); int load(int argc, char **argv); int open_files(int argc, char **argv); @@ -35,6 +36,8 @@ int main(int argc, char **argv) { case 'i': if(!strcmp(progname+1, "nterrupts")) return interrupts(argc, argv); + if(!strncmp(progname+1, "f_err_", 6)) + return if_err_(argc, argv); break; case 'l': if(!strcmp(progname+1, "oad")) From 339b8f43a96583dcef3d6b1590ac2669418195ad Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Jan 2009 12:48:30 +0000 Subject: [PATCH 09/11] added #define PROC_STAT "/proc/stat" --- tools/munin-plugins-busybox/common.h | 2 ++ tools/munin-plugins-busybox/cpu.c | 16 ++++++++-------- tools/munin-plugins-busybox/forks.c | 10 +++++----- tools/munin-plugins-busybox/interrupts.c | 8 ++++---- tools/munin-plugins-busybox/swap.c | 13 +++++++------ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/tools/munin-plugins-busybox/common.h b/tools/munin-plugins-busybox/common.h index 67a5bebc..8db440a9 100644 --- a/tools/munin-plugins-busybox/common.h +++ b/tools/munin-plugins-busybox/common.h @@ -1,6 +1,8 @@ #ifndef COMMON_H #define COMMON_H +#define PROC_STAT "/proc/stat" + int writeyes(void); int writeno(const char *); diff --git a/tools/munin-plugins-busybox/cpu.c b/tools/munin-plugins-busybox/cpu.c index 171a3d3c..9f3483f8 100644 --- a/tools/munin-plugins-busybox/cpu.c +++ b/tools/munin-plugins-busybox/cpu.c @@ -19,8 +19,8 @@ int cpu(int argc, char **argv) { if(s && !strcmp(s, "yes")) scaleto100=1; - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { @@ -37,7 +37,7 @@ int cpu(int argc, char **argv) { fclose(f); if(ncpu < 1 || extinfo < 4) { - fputs("cannot parse /proc/stat\n", stderr); + fputs("cannot parse " PROC_STAT "\n", stderr); return 1; } @@ -114,14 +114,14 @@ int cpu(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { @@ -152,6 +152,6 @@ int cpu(int argc, char **argv) { } } fclose(f); - fputs("no cpu line found in /proc/stat\n", stderr); + fputs("no cpu line found in " PROC_STAT "\n", stderr); return 1; } diff --git a/tools/munin-plugins-busybox/forks.c b/tools/munin-plugins-busybox/forks.c index fa4dadb4..3d4a198e 100644 --- a/tools/munin-plugins-busybox/forks.c +++ b/tools/munin-plugins-busybox/forks.c @@ -21,14 +21,14 @@ int forks(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { @@ -39,6 +39,6 @@ int forks(int argc, char **argv) { } } fclose(f); - fputs("no processes line found in /proc/stat\n", stderr); + fputs("no processes line found in " PROC_STAT "\n", stderr); return 1; } diff --git a/tools/munin-plugins-busybox/interrupts.c b/tools/munin-plugins-busybox/interrupts.c index 2755ccf6..8c800c61 100644 --- a/tools/munin-plugins-busybox/interrupts.c +++ b/tools/munin-plugins-busybox/interrupts.c @@ -26,14 +26,14 @@ int interrupts(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { diff --git a/tools/munin-plugins-busybox/swap.c b/tools/munin-plugins-busybox/swap.c index 1a270fe8..3decfbb0 100644 --- a/tools/munin-plugins-busybox/swap.c +++ b/tools/munin-plugins-busybox/swap.c @@ -27,10 +27,10 @@ int swap(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/stat", R_OK)) + if(0 == access(PROC_STAT, R_OK)) return writeyes(); else - return writeno("/proc/stat not readable"); + return writeno(PROC_STAT " not readable"); } } if(!access("/proc/vmstat", F_OK)) { @@ -56,15 +56,16 @@ int swap(int argc, char **argv) { } return 0; } else { - if(!(f=fopen("/proc/stat", "r"))) { - fputs("cannot open /proc/stat\n", stderr); + if(!(f=fopen(PROC_STAT, "r"))) { + fputs("cannot open " PROC_STAT "\n", stderr); return 1; } while(fgets(buff, 256, f)) { if(!strncmp(buff, "swap ", 5)) { fclose(f); if(2 != sscanf(buff+5, "%d %d", &in, &out)) { - fputs("bad data on /proc/stat\n", stderr); + fputs("bad data on " PROC_STAT "\n", + stderr); return 1; } printf("swap_in.value %d\nswap_out.value %d\n", in, out); @@ -72,7 +73,7 @@ int swap(int argc, char **argv) { } } fclose(f); - fputs("no swap line found in /proc/stat\n", stderr); + fputs("no swap line found in " PROC_STAT "\n", stderr); return 1; } } From 611bfb05808041e6841b41cb5230515611c79d79 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Jan 2009 12:56:20 +0000 Subject: [PATCH 10/11] made more paths be macros --- tools/munin-plugins-busybox/entropy.c | 8 ++++--- tools/munin-plugins-busybox/fw_packets.c | 12 ++++++----- tools/munin-plugins-busybox/load.c | 8 ++++--- tools/munin-plugins-busybox/open_files.c | 26 ++++++++++++++--------- tools/munin-plugins-busybox/open_inodes.c | 12 ++++++----- 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/tools/munin-plugins-busybox/entropy.c b/tools/munin-plugins-busybox/entropy.c index 4a5d8468..cc7791fd 100644 --- a/tools/munin-plugins-busybox/entropy.c +++ b/tools/munin-plugins-busybox/entropy.c @@ -2,6 +2,8 @@ #include #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; } diff --git a/tools/munin-plugins-busybox/fw_packets.c b/tools/munin-plugins-busybox/fw_packets.c index 06367dde..8e94fdea 100644 --- a/tools/munin-plugins-busybox/fw_packets.c +++ b/tools/munin-plugins-busybox/fw_packets.c @@ -4,6 +4,8 @@ #include #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; } diff --git a/tools/munin-plugins-busybox/load.c b/tools/munin-plugins-busybox/load.c index c894f5e2..27e18437 100644 --- a/tools/munin-plugins-busybox/load.c +++ b/tools/munin-plugins-busybox/load.c @@ -3,6 +3,8 @@ #include #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; } diff --git a/tools/munin-plugins-busybox/open_files.c b/tools/munin-plugins-busybox/open_files.c index 3f82c8b5..9eb5c3d7 100644 --- a/tools/munin-plugins-busybox/open_files.c +++ b/tools/munin-plugins-busybox/open_files.c @@ -3,18 +3,21 @@ #include #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); diff --git a/tools/munin-plugins-busybox/open_inodes.c b/tools/munin-plugins-busybox/open_inodes.c index bc20cc60..d9e86577 100644 --- a/tools/munin-plugins-busybox/open_inodes.c +++ b/tools/munin-plugins-busybox/open_inodes.c @@ -3,6 +3,8 @@ #include #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); From 5dcd2ea54d63682993bb7cbbf7c535c24875ce1d Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Mon, 28 Jan 2013 12:57:51 +0100 Subject: [PATCH 11/11] relicense as GPLv2 --- tools/munin-plugins-busybox/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/munin-plugins-busybox/README b/tools/munin-plugins-busybox/README index 3e1457e0..4f8c56be 100644 --- a/tools/munin-plugins-busybox/README +++ b/tools/munin-plugins-busybox/README @@ -30,7 +30,7 @@ replace symlinks in /etc/munin/plugins/ with symlinks to this binary. License? ~~~~~~~~ (C) 2008 Helmut Grohne -GPLv3 applies to *.c *.h and Makefile +At your choice GPLv2 or GPLv3 applies to *.c *.h and Makefile # vim7:spelllang=en # vim:textwidth=75