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>
* - honor sensors.conf's ignored
* - config Sensor option
* - config IgnoreSelected option
* - 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"
**/
#include "collectd.h"
static const char *config_keys[] =
{
"Sensor",
static const char *config_keys[] =
{
"Sensor",
+ "IgnoreSelected",
+ "SensorConfigFile"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
# ifndef SENSORS_CONF_PATH
# define SENSORS_CONF_PATH "/etc/sensors.conf"
# endif
# 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)
/* #endif SENSORS_API_VERSION < 0x400 */
#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
struct featurelist *next;
} featurelist_t;
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 */
/* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
#else /* if SENSORS_API_VERSION >= 0x500 */
-static const char *conffile = SENSORS_CONF_PATH;
featurelist_t *first_feature = NULL;
static ignorelist_t *sensor_list;
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 SENSORS_API_VERSION < 0x400
/* full chip name logic borrowed from lm_sensors */
if (sensor_list == NULL)
sensor_list = ignorelist_create (1);
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))
{
{
if (ignorelist_add (sensor_list, value))
{
static int sensors_load_conf (void)
{
static int sensors_load_conf (void)
{
+ static int call_once = 0;
+
+ FILE *fh = NULL;
featurelist_t *last_feature = NULL;
const sensors_chip_name *chip;
int chip_num;
featurelist_t *last_feature = NULL;
const sensors_chip_name *chip;
int chip_num;
-
- 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;
- }
- 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);
+ 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);
}
status = sensors_init (fh);
+ if (fh)
+ fclose (fh);
+
if (status != 0)
{
ERROR ("sensors plugin: Cannot initialize sensors. "
if (status != 0)
{
ERROR ("sensors plugin: Cannot initialize sensors. "
- sensors_config_mtime = statbuf.st_mtime;
-
#if SENSORS_API_VERSION < 0x400
chip_num = 0;
while ((chip = sensors_get_detected_chips (&chip_num)) != NULL)
#if SENSORS_API_VERSION < 0x400
chip_num = 0;
while ((chip = sensors_get_detected_chips (&chip_num)) != NULL)