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

38 lines
999 B
C
Raw Normal View History

2008-06-21 13:33:06 +02:00
#include <string.h>
#include <stdio.h>
#include "common.h"
2009-01-23 13:56:20 +01:00
#define ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail"
2008-06-21 13:33:06 +02:00
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();
}
2009-01-23 13:56:20 +01:00
if(!(f=fopen(ENTROPY_AVAIL, "r"))) {
fputs("cannot open " ENTROPY_AVAIL "\n", stderr);
2008-06-21 13:33:06 +02:00
return 1;
}
if(1 != fscanf(f, "%d", &entropy)) {
2009-01-23 13:56:20 +01:00
fputs("cannot read from " ENTROPY_AVAIL "\n", stderr);
2008-06-21 13:33:06 +02:00
fclose(f);
return 1;
}
fclose(f);
printf("entropy.value %d\n", entropy);
return 0;
}