summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f11e288)
raw | patch | inline | side by side (parent: f11e288)
author | Florian Forster <octo@collectd.org> | |
Mon, 12 Mar 2012 12:35:38 +0000 (13:35 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 12 Mar 2012 12:35:38 +0000 (13:35 +0100) |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/ethstat.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 01f024dd17b9b3b9273740e32eda2c6d0fb1745a..befb7abae403abd7d7acfde74de1fa7bdb847912 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#<Plugin ethstat>
# Interface "eth0"
+# Map "rx_csum_offload_errors" "if_rx_errors" "checksum_offload"
+# Map "multicast" "if_multicast"
#</Plugin>
#<Plugin exec>
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 765d2ac7afd9c0c46041ba5bac4c9e8ab9878f71..bd14d0e6fa8d2e805578edfc5ae0704c8528c02c 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
<Plugin "ethstat">
Interface "eth0"
+ Map "rx_csum_offload_errors" "if_rx_errors" "checksum_offload"
+ Map "multicast" "if_multicast"
</Plugin>
B<Options:>
Collect statistical information about interface I<Name>.
+=item B<Map> I<Name> I<Type> [I<TypeInstance>]
+
+By default, the plugin will submit values as type C<derive> and I<type
+instance> set to I<Name>, the name of the metric as reported by the driver. If
+an appropriate B<Map> option exists, the given I<Type> and, optionally,
+I<TypeInstance> will be used.
+
=back
=head2 Plugin C<exec>
diff --git a/src/ethstat.c b/src/ethstat.c
index b280a585ba69c52e8194d9e576265c58f4163714..490a9bf69ac54610c30a55feb532ed7b8170702f 100644 (file)
--- a/src/ethstat.c
+++ b/src/ethstat.c
#include "common.h"
#include "plugin.h"
#include "configfile.h"
+#include "utils_avltree.h"
#if HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
# include <linux/ethtool.h>
#endif
-static const char *config_keys[] =
+struct value_map_s
{
- "Interface"
+ char type[DATA_MAX_NAME_LEN];
+ char type_instance[DATA_MAX_NAME_LEN];
};
-static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+typedef struct value_map_s value_map_t;
static char **interfaces = NULL;
static size_t interfaces_num = 0;
-static int ethstat_config (const char *key, const char *value)
+static c_avl_tree_t *value_map = NULL;
+
+static int ethstat_add_interface (const oconfig_item_t *ci) /* {{{ */
{
- if (strcasecmp ("Interface", key) == 0)
- {
- char **tmp;
-
- tmp = realloc (interfaces,
- sizeof (*interfaces) * (interfaces_num + 1));
- if (tmp == NULL)
- return (-1);
- interfaces = tmp;
-
- interfaces[interfaces_num] = strdup (value);
- if (interfaces[interfaces_num] == NULL)
- {
- ERROR ("ethstat plugin: strdup() failed.");
- return (-1);
- }
-
- interfaces_num++;
- INFO("ethstat plugin: Registred interface %s", value);
- }
- return (0);
-}
+ char **tmp;
+ int status;
+
+ tmp = realloc (interfaces,
+ sizeof (*interfaces) * (interfaces_num + 1));
+ if (tmp == NULL)
+ return (-1);
+ interfaces = tmp;
+
+ status = cf_util_get_string (ci, interfaces + interfaces_num);
+ if (status != 0)
+ return (status);
+
+ interfaces_num++;
+ INFO("ethstat plugin: Registred interface %s",
+ interfaces[interfaces_num - 1]);
+
+ return (0);
+} /* }}} int ethstat_add_interface */
+
+static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */
+{
+ value_map_t *map;
+ int status;
+
+ if ((ci->values_num < 2)
+ || (ci->values_num > 3)
+ || (ci->values[0].type != OCONFIG_TYPE_STRING)
+ || (ci->values[1].type != OCONFIG_TYPE_STRING)
+ || ((ci->values_num == 3)
+ && (ci->values[2].type != OCONFIG_TYPE_STRING)))
+ {
+ ERROR ("ethstat plugin: The %s option requires "
+ "two or three string arguments.", ci->key);
+ return (-1);
+ }
+
+ map = malloc (sizeof (*map));
+ if (map == NULL)
+ {
+ ERROR ("ethstat plugin: malloc(3) failed.");
+ return (ENOMEM);
+ }
+ memset (map, 0, sizeof (*map));
+
+ sstrncpy (map->type, ci->values[1].value.string, sizeof (map->type));
+ if (ci->values_num == 2)
+ sstrncpy (map->type_instance, ci->values[2].value.string,
+ sizeof (map->type_instance));
+
+ if (value_map == NULL)
+ {
+ value_map = c_avl_create ((void *) strcmp);
+ if (value_map == NULL)
+ {
+ sfree (map);
+ ERROR ("ethstat plugin: c_avl_create() failed.");
+ return (-1);
+ }
+ }
+
+ status = c_avl_insert (value_map,
+ /* key = */ ci->values[0].value.string,
+ /* value = */ map);
+ if (status != 0)
+ {
+ sfree (map);
+ if (status > 0)
+ ERROR ("ethstat plugin: Multiple mappings for \"%s\".",
+ ci->values[0].value.string);
+ else
+ ERROR ("ethstat plugin: c_avl_insert(\"%s\") failed.",
+ ci->values[0].value.string);
+ return (-1);
+ }
+
+ return (0);
+} /* }}} int ethstat_add_map */
+
+static int ethstat_config (oconfig_item_t *ci) /* {{{ */
+{
+ int i;
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("Interface", child->key) == 0)
+ ethstat_add_interface (child);
+ else if (strcasecmp ("Map", child->key) == 0)
+ ethstat_add_map (child);
+ else
+ WARNING ("ethstat plugin: The config option \"%s\" is unknown.",
+ child->key);
+ }
+
+ return (0);
+} /* }}} */
static void ethstat_submit_value (const char *device,
const char *type_instance, derive_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
+ value_map_t *map = NULL;
+
+ if (value_map != NULL)
+ c_avl_get (value_map, type_instance, (void *) &map);
values[0].derive = value;
vl.values = values;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ethstat", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, device, sizeof (vl.plugin_instance));
- sstrncpy (vl.type, "derive", sizeof (vl.type));
- sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ if (map != NULL)
+ {
+ sstrncpy (vl.type, map->type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, map->type_instance,
+ sizeof (vl.type_instance));
+ }
+ else
+ {
+ sstrncpy (vl.type, "derive", sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ }
plugin_dispatch_values (&vl);
}
void module_register (void)
{
- plugin_register_config ("ethstat", ethstat_config,
- config_keys, config_keys_num);
+ plugin_register_complex_config ("ethstat", ethstat_config);
plugin_register_read ("ethstat", ethstat_read);
}
+
+/* vim: set sw=2 sts=2 et fdm=marker : */