summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 558a6a1)
raw | patch | inline | side by side (parent: 558a6a1)
author | Florian Forster <octo@huhu.verplant.org> | |
Mon, 18 Jun 2007 15:20:07 +0000 (17:20 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Mon, 18 Jun 2007 15:20:07 +0000 (17:20 +0200) |
With this option hosts can be queried in different intervals, reducing the load
on devices with little CPU power, such as switches.
on devices with little CPU power, such as switches.
src/collectd-snmp.pod | patch | blob | history | |
src/snmp.c | patch | blob | history |
diff --git a/src/collectd-snmp.pod b/src/collectd-snmp.pod
index c19b8a00c0cb03d8f6f449e049e40387f7f76456..22d6e37c5c69cc319b4fa3c2f44e68efdb3d2d9a 100644 (file)
--- a/src/collectd-snmp.pod
+++ b/src/collectd-snmp.pod
Version 1
Community "community_string"
Collect "std_traffic"
+ Inverval 120
</Host>
<Host "some.server.mydomain.org">
Address "192.168.0.42"
Version 1
Community "more_communities"
Collect "powerplus_voltge_input"
+ Interval 300
</Host>
</Plugin>
above. Since the config file is read top-down you need to define the data
before using it here.
+=item B<Interval> I<Seconds>
+
+Collect data from this host every I<Seconds> seconds. This value needs to be a
+multiple of the global B<Interval> setting and, if it is not, will be rounded
+B<down> to one and a warning is logged in this case. So if your global
+B<Interval> is set to I<10> and you configure I<25> here, it's rounded down to
+I<20>. By default the global B<Interval> setting will be used.
+
+This option is meant for devices with not much CPU power, e.E<nbsp>g. network
+equipment such as switches, embedded devices, rack monitoring systems and so
+on. Since the B<Step> of generated RRD files depends on this setting it's
+wise to select a reasonable value once and never change it.
+
=back
=head1 BUGS
diff --git a/src/snmp.c b/src/snmp.c
index 7473341f67c5aceb061c775271c403f42e9453e4..ec4a696c7ced5c98e88b83933e72000e504847da 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
char *community;
int version;
struct snmp_session sess;
+ uint16_t skip_num;
+ uint16_t skip_left;
data_definition_t **data_list;
int data_list_len;
struct host_definition_s *next;
/*
* Private variables
*/
-data_definition_t *data_head = NULL;
-host_definition_t *host_head = NULL;
+static data_definition_t *data_head = NULL;
+static host_definition_t *host_head = NULL;
/*
* Private functions
/*
* Callgraph for the config stuff:
* csnmp_config
+ * +-> call_snmp_init_once
* +-> csnmp_config_add_data
* ! +-> csnmp_config_add_data_type
* ! +-> csnmp_config_add_data_table
* ! +-> csnmp_config_add_data_instance
* ! +-> csnmp_config_add_data_values
* +-> csnmp_config_add_host
- * +-> csnmp_config_add_host_collect
+ * +-> csnmp_config_add_host_address
+ * +-> csnmp_config_add_host_community
+ * +-> csnmp_config_add_host_version
+ * +-> csnmp_config_add_host_collect
+ * +-> csnmp_config_add_host_interval
*/
static void call_snmp_init_once (void)
{
return (0);
} /* int csnmp_config_add_host_collect */
+static int csnmp_config_add_host_interval (host_definition_t *hd, oconfig_item_t *ci)
+{
+ int interval;
+
+ if ((ci->values_num != 1)
+ || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+ {
+ WARNING ("snmp plugin: The `Interval' config option needs exactly one number argument.");
+ return (-1);
+ }
+
+ interval = (int) ci->values[0].value.number;
+ hd->skip_num = interval / interval_g;
+ if (hd->skip_num < 1)
+ hd->skip_num = 1;
+
+ if ((hd->skip_num * interval_g) != interval)
+ {
+ WARNING ("snmp plugin: Data for host `%s' will be collected every %i seconds.",
+ hd->name, hd->skip_num * interval_g);
+ }
+
+ return (0);
+} /* int csnmp_config_add_host_interval */
+
static int csnmp_config_add_host (oconfig_item_t *ci)
{
host_definition_t *hd;
snmp_sess_init (&hd->sess);
hd->sess.version = SNMP_VERSION_2c;
+ hd->skip_num = 1;
+ hd->skip_left = 0;
+
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
status = csnmp_config_add_host_version (hd, option);
else if (strcasecmp ("Collect", option->key) == 0)
csnmp_config_add_host_collect (hd, option);
+ else if (strcasecmp ("Interval", option->key) == 0)
+ csnmp_config_add_host_interval (hd, option);
else
{
WARNING ("snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.", option->key);
strncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ vl.interval = interval_g * host->skip_num;
+
req = snmp_pdu_create (SNMP_MSG_GET);
if (req == NULL)
{
static int csnmp_read (void)
{
host_definition_t *host;
+ time_t now;
if (host_head == NULL)
{
return (-1);
}
+ now = time (NULL);
+
for (host = host_head; host != NULL; host = host->next)
+ {
+ host->skip_left--;
+ if (host->skip_left > 0)
+ continue;
+
csnmp_read_host (host);
+ host->skip_left = host->skip_num;
+ } /* for (host) */
+
return (0);
} /* int csnmp_read */