From: Carlos Vicente Date: Wed, 18 Oct 2017 14:21:56 +0000 (+0000) Subject: Adress reviewer's suggestions and add documentation X-Git-Tag: collectd-5.8.0~37^2~2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=52cc5cef3aa8038e00b24c3b9688f8826a49cce5;p=collectd.git Adress reviewer's suggestions and add documentation --- diff --git a/src/collectd-snmp.pod b/src/collectd-snmp.pod index edb95060..d615088e 100644 --- a/src/collectd-snmp.pod +++ b/src/collectd-snmp.pod @@ -36,6 +36,8 @@ collectd-snmp - Documentation of collectd's C Community "community_string" Collect "std_traffic" Interval 120 + Timeout 10 + Retries 1 Address "192.168.0.42" @@ -60,6 +62,8 @@ collectd-snmp - Documentation of collectd's C Community "more_communities" Collect "powerplus_voltge_input" Interval 300 + Timeout 5 + Retries 5 @@ -78,7 +82,7 @@ and ten threads are used. =head1 CONFIGURATION Since the aim of the C is to provide a generic interface to SNMP, -it's configuration is not trivial and may take some time. +its configuration is not trivial and may take some time. Since the C library is used you can use all the environment variables that are interpreted by that package. See L for more details. @@ -281,6 +285,15 @@ switches, embedded devices, rack monitoring systems and so on. Since the B of generated RRD files depends on this setting it's wise to select a reasonable value once and never change it. +=item B I + +How long to wait for a response. The C library default is 1 second. + +=item B I + +The number of times that a query should be retried after the Timeout expires. +The C library default is 5. + =back =head1 SEE ALSO diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 5f58a6e9..425f1ddf 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1316,6 +1316,8 @@ # Community "community_string" # Collect "std_traffic" # Interval 120 +# Timeout 10 +# Retries 1 # # # Address "192.168.0.42" @@ -1329,6 +1331,8 @@ # Community "more_communities" # Collect "powerplus_voltge_input" # Interval 300 +# Timeout 5 +# Retries 5 # # diff --git a/src/snmp.c b/src/snmp.c index c74d7656..f27e64ff 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -71,7 +71,7 @@ struct host_definition_s { char *name; char *address; int version; - int timeout; + cdtime_t timeout; int retries; /* snmpv1/2 options */ @@ -451,48 +451,6 @@ static int csnmp_config_add_host_version(host_definition_t *hd, return 0; } /* int csnmp_config_add_host_address */ -static int csnmp_config_add_host_timeout(host_definition_t *hd, - oconfig_item_t *ci) { - int timeout; - - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) { - WARNING("snmp plugin: `Timeout' must be a number"); - return -1; - } - - timeout = (int)ci->values[0].value.number; - if (timeout < 0) { - WARNING("snmp plugin: `Timeout' must not be negative"); - return -1; - } - - /* net-snmp library timeout is in microseconds */ - hd->timeout = timeout * 1000000; - - return 0; -} /* int csnmp_config_add_host_timeout */ - -static int csnmp_config_add_host_retries(host_definition_t *hd, - oconfig_item_t *ci) { - int retries; - - - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) { - WARNING("snmp plugin: `Retries' must be a number"); - return -1; - } - - retries = (int)ci->values[0].value.number; - if (retries < 0) { - WARNING("snmp plugin: `Retries' must not be negative"); - return -1; - } - - hd->retries = retries; - - return 0; -} /* int csnmp_config_add_host_retries */ - static int csnmp_config_add_host_collect(host_definition_t *host, oconfig_item_t *ci) { data_definition_t *data; @@ -641,8 +599,8 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { hd->sess_handle = NULL; hd->interval = 0; - /* A negative value means that we have not set a timeout or retry value */ - hd->timeout = -1; + /* These mean that we have not set a timeout or retry value */ + hd->timeout = 0xFFFFFFFFFFFFFFFF; hd->retries = -1; for (int i = 0; i < ci->children_num; i++) { @@ -656,9 +614,9 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { else if (strcasecmp("Version", option->key) == 0) status = csnmp_config_add_host_version(hd, option); else if (strcasecmp("Timeout", option->key) == 0) - status = csnmp_config_add_host_timeout(hd, option); + cf_util_get_cdtime(option, &hd->timeout); else if (strcasecmp("Retries", option->key) == 0) - status = csnmp_config_add_host_retries(hd, option); + cf_util_get_int(option, &hd->retries); else if (strcasecmp("Collect", option->key) == 0) csnmp_config_add_host_collect(hd, option); else if (strcasecmp("Interval", option->key) == 0) @@ -856,8 +814,9 @@ static void csnmp_host_open_session(host_definition_t *host) { } /* Set timeout & retries, if they have been changed from the default */ - if (host->timeout >= 0) { - sess.timeout = host->timeout; + if (host->timeout != 0xFFFFFFFFFFFFFFFF) { + /* net-snmp expects microseconds */ + sess.timeout = CDTIME_T_TO_US(host->timeout); } if (host->retries >= 0) { sess.retries = host->retries;