]> arthur.barton.de Git - netdata.git/blob - src/proc_sys_kernel_random_entropy_avail.c
build: migrate to autotools
[netdata.git] / src / proc_sys_kernel_random_entropy_avail.c
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #include "common.h"
8 #include "appconfig.h"
9 #include "procfile.h"
10 #include "rrd.h"
11 #include "plugin_proc.h"
12
13 int do_proc_sys_kernel_random_entropy_avail(int update_every, unsigned long long dt) {
14         static procfile *ff = NULL;
15
16         if(dt) {} ;
17
18         if(!ff) {
19                 char filename[FILENAME_MAX + 1];
20                 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/sys/kernel/random/entropy_avail");
21                 ff = procfile_open(config_get("plugin:proc:/proc/sys/kernel/random/entropy_avail", "filename to monitor", filename), "", PROCFILE_FLAG_DEFAULT);
22         }
23         if(!ff) return 1;
24
25         ff = procfile_readall(ff);
26         if(!ff) return 0; // we return 0, so that we will retry to open it next time
27
28         unsigned long long entropy = strtoull(procfile_lineword(ff, 0, 0), NULL, 10);
29
30         RRDSET *st = rrdset_find_bytype("system", "entropy");
31         if(!st) {
32                 st = rrdset_create("system", "entropy", NULL, "system", "Available Entropy", "entropy", 1000, update_every, RRDSET_TYPE_LINE);
33                 rrddim_add(st, "entropy", NULL, 1, 1, RRDDIM_ABSOLUTE);
34         }
35         else rrdset_next(st);
36
37         rrddim_set(st, "entropy", entropy);
38         rrdset_done(st);
39
40         return 0;
41 }