mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-25 02:18:08 +00:00
initial tree
This commit is contained in:
parent
0cde2ae787
commit
209937078b
15 changed files with 737 additions and 0 deletions
78
tools/munin-plugins-busybox/swap.c
Normal file
78
tools/munin-plugins-busybox/swap.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue