summaryrefslogtreecommitdiff
path: root/load.c
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2008-06-21 11:33:06 +0000
committerHelmut Grohne <helmut@subdivi.de>2008-06-21 11:33:06 +0000
commitf481beb2dc4e6db37ea79f32960cbfa4a148eb90 (patch)
tree9c1f37c19b727d34fd8ab23e6e10b8866d46bb43 /load.c
downloadmunin-plugins-busybox-f481beb2dc4e6db37ea79f32960cbfa4a148eb90.tar.gz
initial tree
Diffstat (limited to 'load.c')
-rw-r--r--load.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/load.c b/load.c
new file mode 100644
index 0000000..c894f5e
--- /dev/null
+++ b/load.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#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;
+}