2 * collectd - src/entropy.c
3 * Copyright (C) 2005,2006 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
27 # define ENTROPY_HAVE_READ 1
29 # define ENTROPY_HAVE_READ 0
32 #define ENTROPY_FILE "/proc/sys/kernel/random/entropy_avail"
34 static data_source_t dsrc[1] =
36 {"entropy", DS_TYPE_GAUGE, 0.0, 4294967295.0}
39 static data_set_t ds =
45 static void entropy_submit (double entropy)
48 value_list_t vl = VALUE_LIST_INIT;
50 values[0].gauge = entropy;
54 vl.time = time (NULL);
55 strcpy (vl.host, hostname);
56 strcpy (vl.plugin, "entropy");
57 strcpy (vl.plugin_instance, "");
58 strcpy (vl.type_instance, "");
60 plugin_dispatch_values ("entropy", &vl);
63 static int entropy_read (void)
70 fh = fopen (ENTROPY_FILE, "r");
74 if (fgets (buffer, sizeof (buffer), fh) == NULL)
81 entropy = atof (buffer);
84 entropy_submit (entropy);
85 #endif /* KERNEL_LINUX */
89 #endif /* ENTROPY_HAVE_READ */
91 void module_register (void)
93 plugin_register_data_set (&ds);
95 plugin_register_read ("entropy", entropy_read);