static void load_submit (double snum, double mnum, double lnum)
{
value_t values[3];
- value_list_t vl;
+ value_list_t vl = VALUE_LIST_INIT;
values[0].gauge = snum;
values[1].gauge = mnum;
vl.values = values;
vl.values_len = 3;
vl.time = time (NULL);
- /* FIXME: do this globally */
- if (gethostname (vl.host, sizeof (vl.host)) != 0)
- {
- syslog (LOG_ERR, "load plugin: gethostname failed: %s",
- strerror (errno));
- return;
- }
+ strcpy (vl.host, hostname);
strcpy (vl.plugin, "load");
strcpy (vl.plugin_instance, "");
strcpy (vl.type_instance, "");
part_header_t *header;
int status;
- value_list_t vl;
+ value_list_t vl = VALUE_LIST_INIT;
char type[DATA_MAX_NAME_LEN];
DBG ("buffer = %p; buffer_len = %i;", buffer, buffer_len);
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Free Software Foundation; only version 2 of the License is applicable.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
#include "collectd.h"
#include "common.h"
#include "plugin.h"
+#include "utils_debug.h"
#define MODULE_NAME "nfs"
# define NFS_HAVE_READ 0
#endif
-static char *nfs2_procedures_file = "nfs2_procedures-%s.rrd";
-static char *nfs3_procedures_file = "nfs3_procedures-%s.rrd";
-
/*
see /proc/net/rpc/nfs
see http://www.missioncriticallinux.com/orph/NFS-Statistics
21 commit
*/
-static char *nfs2_procedures_ds_def[] =
+static data_source_t procedure_dsrc[1] =
+{
+ {"value", DS_TYPE_COUNTER, 0, 4294967295.0}
+};
+
+static data_set_t procedure_ds =
+{
+ "nfs_procedure", 1, procedure_dsrc
+};
+
+static const char *nfs2_procedures_names[] =
{
- "DS:null:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:getattr:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:setattr:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:root:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:lookup:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:readlink:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:read:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:wrcache:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:write:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:create:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:remove:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:rename:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:link:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:symlink:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:mkdir:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:rmdir:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:readdir:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:fsstat:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+ "null",
+ "getattr",
+ "setattr",
+ "root",
+ "lookup",
+ "readlink",
+ "read",
+ "wrcache",
+ "write",
+ "create",
+ "remove",
+ "rename",
+ "link",
+ "symlink",
+ "mkdir",
+ "rmdir",
+ "readdir",
+ "fsstat",
NULL
};
-static int nfs2_procedures_ds_num = 18;
+static int nfs2_procedures_names_num = 18;
-static char *nfs3_procedures_ds_def[] =
+static const char *nfs3_procedures_names[] =
{
- "DS:null:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:getattr:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:setattr:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:lookup:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:access:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:readlink:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:read:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:write:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:create:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:mkdir:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:symlink:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:mknod:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:remove:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:rmdir:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:rename:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:link:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:readdir:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:readdirplus:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:fsstat:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:fsinfo:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:pathconf:COUNTER:"COLLECTD_HEARTBEAT":0:U",
- "DS:commit:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+ "null",
+ "getattr",
+ "setattr",
+ "lookup",
+ "access",
+ "readlink",
+ "read",
+ "write",
+ "create",
+ "mkdir",
+ "symlink",
+ "mknod",
+ "remove",
+ "rmdir",
+ "rename",
+ "link",
+ "readdir",
+ "readdirplus",
+ "fsstat",
+ "fsinfo",
+ "pathconf",
+ "commit",
NULL
};
-static int nfs3_procedures_ds_num = 22;
+static int nfs3_procedures_names_num = 22;
#if HAVE_LIBKSTAT && 0
extern kstat_ctl_t *kc;
/* Possibly TODO: NFSv4 statistics */
-static void nfs_init (void)
+#if 0
+static int nfs_init (void)
{
#if HAVE_LIBKSTAT && 0
kstat_t *ksp_chain;
}
#endif
- return;
-}
+ return (0);
+} /* int nfs_init */
+#endif
#define BUFSIZE 1024
-static void nfs2_procedures_write (char *host, char *inst, char *val)
-{
- char filename[BUFSIZE];
-
- if (snprintf (filename, BUFSIZE, nfs2_procedures_file, inst) > BUFSIZE)
- return;
-
- rrd_update_file (host, filename, val, nfs2_procedures_ds_def,
- nfs2_procedures_ds_num);
-}
-
-static void nfs3_procedures_write (char *host, char *inst, char *val)
-{
- char filename[BUFSIZE];
-
- if (snprintf (filename, BUFSIZE, nfs3_procedures_file, inst) > BUFSIZE)
- return;
-
- rrd_update_file (host, filename, val, nfs3_procedures_ds_def,
- nfs3_procedures_ds_num);
-}
-
#if NFS_HAVE_READ
-static void nfs2_procedures_submit (unsigned long long *val, char *inst)
-{
- char buf[BUFSIZE];
- int retval = 0;
-
- retval = snprintf (buf, BUFSIZE, "%u:%llu:%llu:%llu:%llu:%llu:%llu:"
- "%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:"
- "%llu:%llu:%llu", /* 18x %llu */
- (unsigned int) curtime,
- val[0], val[1], val[2], val[3], val[4], val[5], val[6],
- val[7], val[8], val[9], val[10], val[11], val[12],
- val[13], val[14], val[15], val[16], val[17]);
-
-
- if (retval >= BUFSIZE)
- return;
- else if (retval < 0)
- {
- syslog (LOG_ERR, "nfs: snprintf's format failed: %s", strerror (errno));
- return;
- }
-
- plugin_submit ("nfs2_procedures", inst, buf);
-}
-
-static void nfs3_procedures_submit (unsigned long long *val, char *inst)
+static void nfs_procedures_submit (const char *plugin_instance,
+ unsigned long long *val, const char **names, int len)
{
- char buf[BUFSIZE];
- int retval = 0;
-
- retval = snprintf(buf, BUFSIZE, "%u:%llu:%llu:%llu:%llu:%llu:%llu:"
- "%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:"
- "%llu:%llu:%llu:%llu:%llu:%llu:%llu", /* 22x %llu */
- (unsigned int) curtime,
- val[0], val[1], val[2], val[3], val[4], val[5], val[6],
- val[7], val[8], val[9], val[10], val[11], val[12],
- val[13], val[14], val[15], val[16], val[17], val[18],
- val[19], val[20], val[21]);
-
- if (retval >= BUFSIZE)
- return;
- else if (retval < 0)
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+ int i;
+
+ vl.values = values;
+ vl.values_len = 1;
+ vl.time = time (NULL);
+ strcpy (vl.host, hostname);
+ strcpy (vl.plugin, "nfs");
+ strncpy (vl.plugin_instance, plugin_instance,
+ sizeof (vl.plugin_instance));
+
+ for (i = 0; i < len; i++)
{
- syslog (LOG_ERR, "nfs: snprintf's format failed: %s", strerror (errno));
- return;
+ values[0].counter = val[i];
+ strncpy (vl.type_instance, names[i],
+ sizeof (vl.type_instance));
+ DBG ("%s-%s/nfs_procedure-%s = %llu",
+ vl.plugin, vl.plugin_instance,
+ vl.type_instance, val[i]);
+ plugin_dispatch_values ("nfs_procedure", &vl);
}
-
- plugin_submit("nfs3_procedures", inst, buf);
-}
+} /* void nfs_procedures_submit */
#endif /* NFS_HAVE_READ */
#if KERNEL_LINUX
{
char buffer[BUFSIZE];
+ char plugin_instance[DATA_MAX_NAME_LEN];
+
char *fields[48];
int numfields = 0;
{
numfields = strsplit (buffer, fields, 48);
- if (numfields < 2)
+ if (((numfields - 2) != nfs2_procedures_names_num)
+ && ((numfields - 2)
+ != nfs3_procedures_names_num))
continue;
- if (strncmp (fields[0], "proc2", 5) == 0)
+ if (strcmp (fields[0], "proc2") == 0)
{
int i;
unsigned long long *values;
- if (numfields - 2 != nfs2_procedures_ds_num)
+ if ((numfields - 2) != nfs2_procedures_names_num)
{
- syslog (LOG_WARNING, "nfs: Wrong number of fields (= %i) for NFS2 statistics.", numfields - 2);
+ syslog (LOG_WARNING, "nfs plugin: Wrong "
+ "number of fields (= %i) "
+ "for NFSv2 statistics.",
+ numfields - 2);
continue;
}
- if ((values = (unsigned long long *) malloc (nfs2_procedures_ds_num * sizeof (unsigned long long))) == NULL)
+ snprintf (plugin_instance, sizeof (plugin_instance),
+ "v2%s", inst);
+ plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
+
+ values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long));
+ if (values == NULL)
{
- syslog (LOG_ERR, "nfs: malloc: %s", strerror (errno));
+ syslog (LOG_ERR, "nfs plugin: malloc "
+ "failed: %s",
+ strerror (errno));
continue;
}
- for (i = 0; i < nfs2_procedures_ds_num; i++)
+ for (i = 0; i < nfs2_procedures_names_num; i++)
values[i] = atoll (fields[i + 2]);
- nfs2_procedures_submit (values, inst);
+ nfs_procedures_submit (plugin_instance, values,
+ nfs2_procedures_names,
+ nfs2_procedures_names_num);
free (values);
}
int i;
unsigned long long *values;
- if (numfields - 2 != nfs3_procedures_ds_num)
+ if ((numfields - 2) != nfs3_procedures_names_num)
{
- syslog (LOG_WARNING, "nfs: Wrong number of fields (= %i) for NFS3 statistics.", numfields - 2);
+ syslog (LOG_WARNING, "nfs plugin: Wrong "
+ "number of fields (= %i) "
+ "for NFSv3 statistics.",
+ numfields - 2);
continue;
}
- if ((values = (unsigned long long *) malloc (nfs3_procedures_ds_num * sizeof (unsigned long long))) == NULL)
+ snprintf (plugin_instance, sizeof (plugin_instance),
+ "v3%s", inst);
+ plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
+
+ values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long));
+ if (values == NULL)
{
- syslog (LOG_ERR, "nfs: malloc: %s", strerror (errno));
+ syslog (LOG_ERR, "nfs plugin: malloc "
+ "failed: %s",
+ strerror (errno));
continue;
}
- for (i = 0; i < nfs3_procedures_ds_num; i++)
+ for (i = 0; i < nfs3_procedures_names_num; i++)
values[i] = atoll (fields[i + 2]);
- nfs3_procedures_submit (values, inst);
+ nfs_procedures_submit (plugin_instance, values,
+ nfs3_procedures_names,
+ nfs3_procedures_names_num);
free (values);
}
- }
-}
+ } /* while (fgets (buffer, BUFSIZE, fh) != NULL) */
+} /* void nfs_read_stats_file */
#endif /* defined(KERNEL_LINUX) */
#undef BUFSIZE
#endif
#if NFS_HAVE_READ
-static void nfs_read (void)
+static int nfs_read (void)
{
#if KERNEL_LINUX
FILE *fh;
if (nfs2_ksp_server != NULL)
nfs2_read_kstat (nfs2_ksp_server, "server");
#endif /* defined(HAVE_LIBKSTAT) */
+
+ return (0);
}
-#else
-# define nfs_read NULL
#endif /* NFS_HAVE_READ */
void module_register (void)
{
- plugin_register (MODULE_NAME, nfs_init, nfs_read, NULL);
- plugin_register ("nfs2_procedures", NULL, NULL, nfs2_procedures_write);
- plugin_register ("nfs3_procedures", NULL, NULL, nfs3_procedures_write);
+ plugin_register_data_set (&procedure_ds);
+
+#if NFS_HAVE_READ
+ plugin_register_read ("nfs", nfs_read);
+#endif
}
#undef MODULE_NAME
static char *plugindir = NULL;
+char hostname[DATA_MAX_NAME_LEN] = "localhost";
+
/*
* Static functions
*/
int (*callback) (void);
llentry_t *le;
+ gethostname (hostname, sizeof (hostname));
+
if (list_init == NULL)
return;
le = llist_search (list_data_set, name);
if (le == NULL)
+ {
+ DBG ("No such dataset registered: %s", name);
return (-1);
+ }
ds = (data_set_t *) le->value;
};
typedef struct value_list_s value_list_t;
+#define VALUE_LIST_INIT { NULL, 0, 0, "localhost", "", "", "" }
+
struct data_source_s
{
char name[DATA_MAX_NAME_LEN];
unsigned int delay; /* how many more iterations we still need to wait */
} complain_t;
+extern char hostname[DATA_MAX_NAME_LEN];
+
/*
* NAME
* plugin_set_dir
* - config IgnoreSelected option
**/
+
+
#include "collectd.h"
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
#include "utils_debug.h"
-#define MODULE_NAME "sensors"
-#define MODULE_NAME_VOLTAGE MODULE_NAME"_voltage"
+/*
+ * This weird macro cascade forces the glibc to define `NAN'. I don't know
+ * another way to solve this, so more intelligent solutions are welcome. -octo
+ */
+#ifndef __USE_ISOC99
+# define DISABLE__USE_ISOC99 1
+# define __USE_ISOC99 1
+#endif
+#include <math.h>
+#ifdef DISABLE__USE_ISOC99
+# undef DISABLE__USE_ISOC99
+# undef __USE_ISOC99
+#endif
#if defined(HAVE_SENSORS_SENSORS_H)
# include <sensors/sensors.h>
# define SENSORS_HAVE_READ 0
#endif
-#define BUFSIZE 512
-
-/* temperature and fan sensors */
-static char *ds_def[] =
+static data_source_t data_source[1] =
{
- "DS:value:GAUGE:"COLLECTD_HEARTBEAT":U:U",
- NULL
+ {"value", DS_TYPE_GAUGE, NAN, NAN}
};
-static int ds_num = 1;
-
-/* voltage sensors */
-static char *sensor_voltage_ds_def[] =
+static data_set_t fanspeed_ds =
{
- "DS:voltage:GAUGE:"COLLECTD_HEARTBEAT":U:U",
- NULL
+ "fanspeed", 1, data_source
};
-static int sensor_voltage_ds_num = 1;
-
-/* old naming */
-static char *old_filename_format = "sensors-%s.rrd";
-/* end old naming */
-/* new naming <chip-bus-address/type-feature */
-static char *extended_filename_format = "lm_sensors-%s.rrd";
+static data_set_t temperature_ds =
+{
+ "temperature", 1, data_source
+};
-#define SENSOR_TYPE_UNKNOWN 0
-#define SENSOR_TYPE_VOLTAGE 1
-#define SENSOR_TYPE_FANSPEED 2
-#define SENSOR_TYPE_TEMPERATURE 3
+static data_set_t voltage_ds =
+{
+ "voltage", 1, data_source
+};
#if SENSORS_HAVE_READ
-static char *sensor_type_prefix[] =
+#define SENSOR_TYPE_VOLTAGE 0
+#define SENSOR_TYPE_FANSPEED 1
+#define SENSOR_TYPE_TEMPERATURE 2
+#define SENSOR_TYPE_UNKNOWN 3
+
+static char *sensor_to_type[] =
{
- "unknown",
"voltage",
"fanspeed",
"temperature",
NULL
};
-#endif
-typedef struct sensors_labeltypes {
+struct sensors_labeltypes_s
+{
char *label;
int type;
-} sensors_labeltypes;
+};
+typedef struct sensors_labeltypes_s sensors_labeltypes_t;
/*
* finite list of known labels extracted from lm_sensors
*/
-#if SENSORS_HAVE_READ
-static sensors_labeltypes known_features[] =
+static sensors_labeltypes_t known_features[] =
{
{ "fan1", SENSOR_TYPE_FANSPEED },
{ "fan2", SENSOR_TYPE_FANSPEED },
{ "2.5V", SENSOR_TYPE_VOLTAGE },
{ "2.0V", SENSOR_TYPE_VOLTAGE },
{ "12V", SENSOR_TYPE_VOLTAGE },
- { 0, -1 }
+ { (char *) 0, SENSOR_TYPE_UNKNOWN }
};
-#endif
/* end new naming */
-static char *config_keys[] =
+static const char *config_keys[] =
{
"Sensor",
"IgnoreSelected",
- "ExtendedSensorNaming",
NULL
};
-static int config_keys_num = 3;
+static int config_keys_num = 2;
static ignorelist_t *sensor_list;
-/*
- * sensor_extended_naming:
- * 0 => default is to create chip-feature
- * 1 => use new naming scheme chip-bus-address/type-feature
- */
-static int sensor_extended_naming = 0;
-
-#if SENSORS_HAVE_READ
-# 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;
/* SENSORS_CONF_PATH */
} featurelist_t;
featurelist_t *first_feature = NULL;
-#endif /* if SENSORS_HAVE_READ */
-static int sensors_config (char *key, char *value)
+static int sensors_config (const char *key, const char *value)
{
if (sensor_list == NULL)
sensor_list = ignorelist_create (1);
{
if (ignorelist_add (sensor_list, value))
{
- syslog (LOG_EMERG, MODULE_NAME": Cannot add value to ignorelist.");
+ syslog (LOG_ERR, "sensors plugin: "
+ "Cannot add value to ignorelist.");
return (1);
}
}
|| (strcasecmp (value, "On") == 0))
ignorelist_set_invert (sensor_list, 0);
}
- else if (strcasecmp (key, "ExtendedSensorNaming") == 0)
- {
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
- sensor_extended_naming = 1;
- else
- sensor_extended_naming = 0;
- }
else
{
return (-1);
return (0);
}
-#if SENSORS_HAVE_READ
void sensors_free_features (void)
{
featurelist_t *thisft;
status = stat (conffile, &statbuf);
if (status != 0)
{
- syslog (LOG_ERR, MODULE_NAME": stat(%s) failed: %s",
+ syslog (LOG_ERR, "sensors plugin: stat (%s) failed: %s",
conffile, strerror (errno));
sensors_config_mtime = 0;
}
if (sensors_config_mtime != 0)
{
- syslog (LOG_NOTICE, MODULE_NAME": Reloading config from %s",
+ syslog (LOG_NOTICE, "sensors plugin: Reloading config from %s",
conffile);
sensors_free_features ();
sensors_config_mtime = 0;
fh = fopen (conffile, "r");
if (fh == NULL)
{
- syslog (LOG_ERR, MODULE_NAME": fopen(%s) failed: %s",
+ syslog (LOG_ERR, "sensors plugin: fopen(%s) failed: %s",
conffile, strerror(errno));
return;
}
fclose (fh);
if (status != 0)
{
- syslog (LOG_ERR, MODULE_NAME": Cannot initialize sensors. "
+ syslog (LOG_ERR, "sensors plugin: Cannot initialize sensors. "
"Data will not be collected.");
return;
}
if ((new_feature = (featurelist_t *) malloc (sizeof (featurelist_t))) == NULL)
{
DBG ("malloc: %s", strerror (errno));
- syslog (LOG_ERR, MODULE_NAME": malloc: %s",
+ syslog (LOG_ERR, "sensors plugin: malloc: %s",
strerror (errno));
break;
}
if (first_feature == NULL)
{
sensors_cleanup ();
- syslog (LOG_INFO, MODULE_NAME": lm_sensors reports no features. "
- "Data will not be collected.");
+ syslog (LOG_INFO, "sensors plugin: lm_sensors reports no "
+ "features. Data will not be collected.");
}
} /* void sensors_load_conf */
-#endif /* if SENSORS_HAVE_READ */
-
-static void collectd_sensors_init (void)
-{
- return;
-}
-static void sensors_shutdown (void)
+static int sensors_shutdown (void)
{
-#if SENSORS_HAVE_READ
sensors_free_features ();
-#endif /* if SENSORS_HAVE_READ */
-
ignorelist_free (sensor_list);
-}
-
-static void sensors_voltage_write (char *host, char *inst, char *val)
-{
- char file[BUFSIZE];
- int status;
-
- /* skip ignored in our config */
- if (ignorelist_match (sensor_list, inst))
- return;
-
- /* extended sensor naming */
- if(sensor_extended_naming)
- status = snprintf (file, BUFSIZE, extended_filename_format, inst);
- else
- status = snprintf (file, BUFSIZE, old_filename_format, inst);
-
- if ((status < 1) || (status >= BUFSIZE))
- return;
-
- rrd_update_file (host, file, val, sensor_voltage_ds_def, sensor_voltage_ds_num);
-}
-
-static void sensors_write (char *host, char *inst, char *val)
-{
- char file[BUFSIZE];
- int status;
-
- /* skip ignored in our config */
- if (ignorelist_match (sensor_list, inst))
- return;
-
- /* extended sensor naming */
- if (sensor_extended_naming)
- status = snprintf (file, BUFSIZE, extended_filename_format, inst);
- else
- status = snprintf (file, BUFSIZE, old_filename_format, inst);
-
- if ((status < 1) || (status >= BUFSIZE))
- return;
- rrd_update_file (host, file, val, ds_def, ds_num);
-}
+ return (0);
+} /* int sensors_shutdown */
-#if SENSORS_HAVE_READ
-static void sensors_submit (const char *feat_name,
- const char *chip_prefix, double value, int type)
+static void sensors_submit (const char *plugin_instance,
+ const char *type, const char *type_instance,
+ double val)
{
- char buf[BUFSIZE];
- char inst[BUFSIZE];
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
- if (snprintf (inst, BUFSIZE, "%s-%s", chip_prefix, feat_name)
- >= BUFSIZE)
+ if (ignorelist_match (sensor_list, type_instance))
return;
- /* skip ignored in our config */
- if (ignorelist_match (sensor_list, inst))
- return;
+ values[0].gauge = val;
- if (snprintf (buf, BUFSIZE, "%u:%.3f", (unsigned int) curtime,
- value) >= BUFSIZE)
- return;
+ vl.values = values;
+ vl.values_len = 1;
+ vl.time = time (NULL);
+ strcpy (vl.host, hostname);
+ strcpy (vl.plugin, "sensors");
+ strcpy (vl.plugin_instance, plugin_instance);
+ strcpy (vl.type_instance, type_instance);
- if (type == SENSOR_TYPE_VOLTAGE)
- {
- DBG ("%s: %s/%s, %s", MODULE_NAME_VOLTAGE,
- sensor_type_prefix[type], inst, buf);
- plugin_submit (MODULE_NAME_VOLTAGE, inst, buf);
- }
- else
- {
- DBG ("%s: %s/%s, %s", MODULE_NAME,
- sensor_type_prefix[type], inst, buf);
- plugin_submit (MODULE_NAME, inst, buf);
- }
-}
+ plugin_dispatch_values (type, &vl);
+} /* void sensors_submit */
-static void sensors_read (void)
+static int sensors_read (void)
{
featurelist_t *feature;
double value;
- char chip_fullprefix[BUFSIZE];
+ char chip_fullprefix[512];
+
+ char plugin_instance[DATA_MAX_NAME_LEN];
+ char type_instance[DATA_MAX_NAME_LEN];
sensors_load_conf ();
if (sensors_get_feature (*feature->chip, feature->data->number, &value) < 0)
continue;
- if (sensor_extended_naming)
+ /* full chip name logic borrowed from lm_sensors */
+ if (feature->chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
{
- /* full chip name logic borrowed from lm_sensors */
- if (feature->chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
- {
- if (snprintf (chip_fullprefix, BUFSIZE, "%s-isa-%04x/%s",
- feature->chip->prefix,
- feature->chip->addr,
- sensor_type_prefix[feature->type])
- >= BUFSIZE)
- continue;
- }
- else if (feature->chip->bus == SENSORS_CHIP_NAME_BUS_DUMMY)
- {
- if (snprintf (chip_fullprefix, BUFSIZE, "%s-%s-%04x/%s",
- feature->chip->prefix,
- feature->chip->busname,
- feature->chip->addr,
- sensor_type_prefix[feature->type])
- >= BUFSIZE)
- continue;
- }
- else
- {
- if (snprintf (chip_fullprefix, BUFSIZE, "%s-i2c-%d-%02x/%s",
- feature->chip->prefix,
- feature->chip->bus,
- feature->chip->addr,
- sensor_type_prefix[feature->type])
- >= BUFSIZE)
- continue;
- }
-
- sensors_submit (feature->data->name,
- chip_fullprefix,
- value, feature->type);
+ if (snprintf (plugin_instance, DATA_MAX_NAME_LEN, "%s-isa-%04x",
+ feature->chip->prefix,
+ feature->chip->addr)
+ >= 512)
+ continue;
+ }
+ else if (feature->chip->bus == SENSORS_CHIP_NAME_BUS_DUMMY)
+ {
+ if (snprintf (plugin_instance, 512, "%s-%s-%04x",
+ feature->chip->prefix,
+ feature->chip->busname,
+ feature->chip->addr)
+ >= 512)
+ continue;
}
else
{
- sensors_submit (feature->data->name,
- feature->chip->prefix,
- value, feature->type);
+ if (snprintf (plugin_instance, 512, "%s-i2c-%d-%02x",
+ feature->chip->prefix,
+ feature->chip->bus,
+ feature->chip->addr)
+ >= 512)
+ continue;
}
+
+ strncpy (type_instance, feature->data->name, DATA_MAX_NAME_LEN);
+
+ sensors_submit (plugin_instance,
+ sensor_to_type[feature->type]
+ type_instance,
+ value);
} /* for feature = first_feature .. NULL */
-} /* void sensors_read */
-#else
-# define sensors_read NULL
+} /* int sensors_read */
#endif /* SENSORS_HAVE_READ */
void module_register (void)
{
- plugin_register (MODULE_NAME, collectd_sensors_init, sensors_read, sensors_write);
- plugin_register (MODULE_NAME_VOLTAGE, NULL, NULL, sensors_voltage_write);
- plugin_register_shutdown (MODULE_NAME, sensors_shutdown);
- cf_register (MODULE_NAME, sensors_config, config_keys, config_keys_num);
-}
+ plugin_register_data_set (&fanspeed_ds);
+ plugin_register_data_set (&temperature_ds);
+ plugin_register_data_set (&voltage_ds);
-#undef BUFSIZE
-#undef MODULE_NAME
+#if SENSORS_HAVE_READ
+ plugin_register_config ("sensors", sensors_config,
+ config_keys, config_keys_num);
+ plugin_register_read ("sensors", sensors_read);
+ plugin_register_shutdown ("sensors", sensors_shutdown);
+#endif
+} /* void module_register */
unsigned long long tx)
{
value_t values[2];
- value_list_t vl;
+ value_list_t vl = VALUE_LIST_INIT;
if (check_ignore_if (dev))
return;
vl.values = values;
vl.values_len = 2;
vl.time = time (NULL);
-
- /* FIXME: do this globally */
- if (gethostname (vl.host, sizeof (vl.host)) != 0)
- {
- syslog (LOG_ERR, "load plugin: gethostname failed: %s",
- strerror (errno));
- return;
- }
+ strcpy (vl.host, hostname);
strcpy (vl.plugin, "interface");
strcpy (vl.plugin_instance, "");
strncpy (vl.type_instance, dev, sizeof (vl.type_instance));