From: Florian Forster Date: Sat, 17 Mar 2012 10:18:57 +0000 (+0100) Subject: ethstat plugin: Implement the "MappedOnly" option. X-Git-Tag: collectd-5.1.0~9^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=cc6d0a87fde638e2ad8c44ec5c15d8193439e12d;p=collectd.git ethstat plugin: Implement the "MappedOnly" option. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index befb7aba..f3ef6759 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -340,6 +340,7 @@ # Interface "eth0" # Map "rx_csum_offload_errors" "if_rx_errors" "checksum_offload" # Map "multicast" "if_multicast" +# MappedOnly false # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index bd14d0e6..f89af084 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1300,6 +1300,11 @@ instance> set to I, the name of the metric as reported by the driver. If an appropriate B option exists, the given I and, optionally, I will be used. +=item B B|B + +When set to B, only metrics that can be mapped to to a I will be +collected, all other metrics will be ignored. Defaults to B. + =back =head2 Plugin C diff --git a/src/ethstat.c b/src/ethstat.c index 7507bd97..bc024771 100644 --- a/src/ethstat.c +++ b/src/ethstat.c @@ -1,6 +1,7 @@ /** * collectd - src/ethstat.c * Copyright (C) 2011 Cyril Feraudet + * Copyright (C) 2012 Florian "octo" Forster * * 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 @@ -18,6 +19,7 @@ * * Authors: * Cyril Feraudet + * Florian "octo" Forster **/ #include "collectd.h" @@ -25,6 +27,7 @@ #include "plugin.h" #include "configfile.h" #include "utils_avltree.h" +#include "utils_complain.h" #if HAVE_SYS_IOCTL_H # include @@ -51,6 +54,8 @@ static size_t interfaces_num = 0; static c_avl_tree_t *value_map = NULL; +static _Bool collect_mapped_only = 0; + static int ethstat_add_interface (const oconfig_item_t *ci) /* {{{ */ { char **tmp; @@ -144,6 +149,8 @@ static int ethstat_config (oconfig_item_t *ci) /* {{{ */ ethstat_add_interface (child); else if (strcasecmp ("Map", child->key) == 0) ethstat_add_map (child); + else if (strcasecmp ("MappedOnly", child->key) == 0) + (void) cf_util_get_boolean (child, &collect_mapped_only); else WARNING ("ethstat plugin: The config option \"%s\" is unknown.", child->key); @@ -155,6 +162,8 @@ static int ethstat_config (oconfig_item_t *ci) /* {{{ */ static void ethstat_submit_value (const char *device, const char *type_instance, derive_t value) { + static c_complain_t complain_no_map = C_COMPLAIN_INIT_STATIC; + value_t values[1]; value_list_t vl = VALUE_LIST_INIT; value_map_t *map = NULL; @@ -162,6 +171,16 @@ static void ethstat_submit_value (const char *device, if (value_map != NULL) c_avl_get (value_map, type_instance, (void *) &map); + /* If the "MappedOnly" option is specified, ignore unmapped values. */ + if (collect_mapped_only && (map == NULL)) + { + if (value_map == NULL) + c_complain (LOG_WARNING, &complain_no_map, + "ethstat plugin: The \"MappedOnly\" option has been set to true, " + "but no mapping has been configured. All values will be ignored!"); + return; + } + values[0].derive = value; vl.values = values; vl.values_len = 1;