summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c11d05)
raw | patch | inline | side by side (parent: 4c11d05)
author | Henrique de Moraes Holschuh <hmh@debian.org> | |
Sat, 16 Oct 2010 01:21:57 +0000 (22:21 -0300) | ||
committer | Florian Forster <octo@collectd.org> | |
Tue, 21 Feb 2012 19:49:25 +0000 (20:49 +0100) |
Sensors often require scaling. Also, you often have to disable them, or name
them.
The libsensors config file provides all these facilities. Without it, the
sensor plugin is mostly useless except for some values that are often already
properly scaled by the kernel (some temperatures, some fan tachometers).
In particular, it is utterly useless for voltage monitoring outside of the 3.3V
rails.
The plugin should either evaluate the libsensors config files at startup, or it
should provide facilities to give proper names and first-order polinomial
scaling+offset.
Change-Id: I97312bee5ca33fefe846a8cdc292818d46819574
Signed-off-by: Florian Forster <octo@collectd.org>
them.
The libsensors config file provides all these facilities. Without it, the
sensor plugin is mostly useless except for some values that are often already
properly scaled by the kernel (some temperatures, some fan tachometers).
In particular, it is utterly useless for voltage monitoring outside of the 3.3V
rails.
The plugin should either evaluate the libsensors config files at startup, or it
should provide facilities to give proper names and first-order polinomial
scaling+offset.
Change-Id: I97312bee5ca33fefe846a8cdc292818d46819574
Signed-off-by: Florian Forster <octo@collectd.org>
src/sensors.c | patch | blob | history |
diff --git a/src/sensors.c b/src/sensors.c
index 8391346b4dc611b060633e8e6b1c828d20d7b67a..96a54fca91cb56bc9bb825f93a749b291c2c71c7 100644 (file)
--- a/src/sensors.c
+++ b/src/sensors.c
* - honor sensors.conf's ignored
* - config Sensor option
* - config IgnoreSelected option
+ *
+ * Henrique de Moraes Holschuh <hmh at debian.org>
+ * - use default libsensors config file on API 0x400
+ * - config SensorConfigFile option
**/
#include "collectd.h"
static const char *config_keys[] =
{
"Sensor",
- "IgnoreSelected"
+ "IgnoreSelected",
+ "SensorConfigFile"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
# ifndef SENSORS_CONF_PATH
# define SENSORS_CONF_PATH "/etc/sensors.conf"
# endif
+static const char *conffile = SENSORS_CONF_PATH;
/* #endif SENSORS_API_VERSION < 0x400 */
#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
struct featurelist *next;
} featurelist_t;
-# ifndef SENSORS_CONF_PATH
-# define SENSORS_CONF_PATH "/etc/sensors3.conf"
-# endif
+static const char *conffile = NULL;
/* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
#else /* if SENSORS_API_VERSION >= 0x500 */
"as bug."
#endif
-static const char *conffile = SENSORS_CONF_PATH;
featurelist_t *first_feature = NULL;
static ignorelist_t *sensor_list;
-static time_t sensors_config_mtime = 0;
#if SENSORS_API_VERSION < 0x400
/* full chip name logic borrowed from lm_sensors */
if (sensor_list == NULL)
sensor_list = ignorelist_create (1);
- if (strcasecmp (key, "Sensor") == 0)
+ if (strcasecmp (key, "SensorConfigFile") == 0)
+ {
+ /* we will leak memory here if SensorConfigFile is
+ used more than once, maybe we can just drop support
+ for broken, extremely ancient libsensors? */
+ conffile = strdup (value);
+ }
+ else if (strcasecmp (key, "Sensor") == 0)
{
if (ignorelist_add (sensor_list, value))
{
static int sensors_load_conf (void)
{
- FILE *fh;
+ static int call_once = 0;
+
+ FILE *fh = NULL;
featurelist_t *last_feature = NULL;
const sensors_chip_name *chip;
int chip_num;
- struct stat statbuf;
int status;
-
- status = stat (conffile, &statbuf);
- if (status != 0)
- {
- char errbuf[1024];
- ERROR ("sensors plugin: stat (%s) failed: %s", conffile,
- sstrerror (errno, errbuf, sizeof (errbuf)));
- sensors_config_mtime = 0;
- }
- if ((sensors_config_mtime != 0)
- && (sensors_config_mtime == statbuf.st_mtime))
- return (0);
+ if (call_once)
+ return 0;
- if (sensors_config_mtime != 0)
- {
- NOTICE ("sensors plugin: Reloading config from %s",
- conffile);
- sensors_free_features ();
- sensors_config_mtime = 0;
- }
+ call_once = 1;
- fh = fopen (conffile, "r");
- if (fh == NULL)
+ if (conffile)
{
- char errbuf[1024];
- ERROR ("sensors plugin: fopen(%s) failed: %s", conffile,
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
+ fh = fopen (conffile, "r");
+ if (fh == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("sensors plugin: fopen(%s) failed: %s", conffile,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
}
status = sensors_init (fh);
- fclose (fh);
+ if (fh)
+ fclose (fh);
+
if (status != 0)
{
ERROR ("sensors plugin: Cannot initialize sensors. "
return (-1);
}
- sensors_config_mtime = statbuf.st_mtime;
-
#if SENSORS_API_VERSION < 0x400
chip_num = 0;
while ((chip = sensors_get_detected_chips (&chip_num)) != NULL)