]> arthur.barton.de Git - netdata.git/blob - src/proc_sys_kernel_random_entropy_avail.c
Merge pull request #1998 from ktsaou/master
[netdata.git] / src / proc_sys_kernel_random_entropy_avail.c
1 #include "common.h"
2
3 int do_proc_sys_kernel_random_entropy_avail(int update_every, usec_t dt) {
4     (void)dt;
5
6     static procfile *ff = NULL;
7
8     if(unlikely(!ff)) {
9         char filename[FILENAME_MAX + 1];
10         snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/sys/kernel/random/entropy_avail");
11         ff = procfile_open(config_get("plugin:proc:/proc/sys/kernel/random/entropy_avail", "filename to monitor", filename), "", PROCFILE_FLAG_DEFAULT);
12         if(unlikely(!ff)) return 1;
13     }
14
15     ff = procfile_readall(ff);
16     if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
17
18     unsigned long long entropy = str2ull(procfile_lineword(ff, 0, 0));
19
20     RRDSET *st = rrdset_find_bytype_localhost("system", "entropy");
21     if(unlikely(!st)) {
22         st = rrdset_create_localhost("system", "entropy", NULL, "entropy", NULL, "Available Entropy", "entropy", 1000
23                                      , update_every, RRDSET_TYPE_LINE);
24         rrddim_add(st, "entropy", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
25     }
26     else rrdset_next(st);
27
28     rrddim_set(st, "entropy", entropy);
29     rrdset_done(st);
30
31     return 0;
32 }