| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "plugin_proc.h" |
| 4 | |
| 5 | int do_proc_sys_kernel_random_entropy_avail(int update_every, usec_t dt) { |
| 6 | (void)dt; |
| 7 | |
| 8 | static procfile *ff = NULL; |
| 9 | |
| 10 | if(unlikely(!ff)) { |
| 11 | char filename[FILENAME_MAX + 1]; |
| 12 | snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/sys/kernel/random/entropy_avail"); |
| 13 | ff = procfile_open(inicfg_get(&netdata_config, "plugin:proc:/proc/sys/kernel/random/entropy_avail", "filename to monitor", filename), "", PROCFILE_FLAG_DEFAULT); |
| 14 | if(unlikely(!ff)) return 1; |
| 15 | } |
| 16 | |
| 17 | ff = procfile_readall(ff); |
| 18 | if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time |
| 19 | |
| 20 | unsigned long long entropy = str2ull(procfile_lineword(ff, 0, 0), NULL); |
| 21 | |
| 22 | static RRDSET *st = NULL; |
| 23 | static RRDDIM *rd = NULL; |
| 24 | |
| 25 | if(unlikely(!st)) { |
| 26 | st = rrdset_create_localhost( |
| 27 | "system" |
| 28 | , "entropy" |
| 29 | , NULL |
| 30 | , "entropy" |
| 31 | , NULL |
| 32 | , "Available Entropy" |
| 33 | , "entropy" |
| 34 | , PLUGIN_PROC_NAME |
| 35 | , "/proc/sys/kernel/random/entropy_avail" |
| 36 | , NETDATA_CHART_PRIO_SYSTEM_ENTROPY |
| 37 | , update_every |
| 38 | , RRDSET_TYPE_LINE |
| 39 | ); |
| 40 | |
| 41 | rd = rrddim_add(st, "entropy", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 42 | } |
| 43 | |
| 44 | rrddim_set_by_pointer(st, rd, entropy); |
| 45 | rrdset_done(st); |
| 46 | return 0; |
| 47 | } |