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/load.c

40 lines
880 B
C
Raw Normal View History

2008-06-21 13:33:06 +02:00
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "common.h"
2009-01-23 13:56:20 +01:00
#define PROC_LOADAVG "/proc/loadavg"
2008-06-21 13:33:06 +02:00
int load(int argc, char **argv) {
FILE *f;
float val;
if(argc > 1) {
if(!strcmp(argv[1], "config")) {
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");
2013-01-28 16:35:25 +01:00
printf("load.warning %d\nload.critical %d\n",
getenvint("load_warn", 10),
getenvint("load_crit", 120));
2008-06-21 13:33:06 +02:00
return 0;
}
if(!strcmp(argv[1], "autoconf"))
return writeyes();
}
2009-01-23 13:56:20 +01:00
if(!(f=fopen(PROC_LOADAVG, "r"))) {
fputs("cannot open " PROC_LOADAVG "\n", stderr);
2008-06-21 13:33:06 +02:00
return 1;
}
if(1 != fscanf(f, "%*f %f", &val)) {
2009-01-23 13:56:20 +01:00
fputs("cannot read from " PROC_LOADAVG "\n", stderr);
2008-06-21 13:33:06 +02:00
fclose(f);
return 1;
}
fclose(f);
printf("load.value %.2f\n", val);
return 0;
}