Hi List,

I've implemented a feature for the snmp plugin (see attached patch) and
would like to solicit opinions on it's possible inclusion upstream. It
is to have a special value, e.g. "__SUBID__" within the configured
InstancePrefix value that gets replaced with the table entry's subid.
For example, if you're collecting interface throughput with the standard
ifInOctets and ifOutOctets, you can set Instance to "IF-MIB::ifDescr"
and InstancePrefix to "__SUBID__: ". The resulting rrd combines the
subid, the constant string and the ifDescr like "$host/snmp/1: Joe
Customer.rrd".

I was motivated to implement this because:

* Having the interface name in the file name simplifies the front-end,
which needs no further information to present informative graphs.
* Having the interface name in the file name allows us to create a new
graph simply by relabeling, so when we repurpose a port for instance by
assigning a new customer to it we don't have one customer's history on
another customer's current graph.
* Having only the interface name isn't unique enough, since multiple
interfaces could have no name or be mistakenly labeled the same.

Thanks,
Luke Heberling
--- a/src/snmp.c	2011-03-27 09:35:49.000000000 -0700
+++ b/src/snmp.c	2011-04-28 11:21:51.000000000 -0700
@@ -1119,20 +1119,39 @@ static int csnmp_dispatch_table (host_de
 
     sstrncpy (vl.type, data->type, sizeof (vl.type));
 
-    {
-      char temp[DATA_MAX_NAME_LEN];
-
-      if (instance_list_ptr == NULL)
-	ssnprintf (temp, sizeof (temp), "%"PRIu32, (uint32_t) subid);
+    if (instance_list_ptr == NULL)
+      if (data->instance_prefix == NULL)
+        ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+		"%"PRIu32, (uint32_t) subid);
       else
-	sstrncpy (temp, instance_list_ptr->instance, sizeof (temp));
-
+        ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+		"%s%"PRIu32, vl.type_instance, (uint32_t) subid);
+    else
       if (data->instance_prefix == NULL)
-	sstrncpy (vl.type_instance, temp, sizeof (vl.type_instance));
+        sstrncpy (vl.type_instance, instance_list_ptr->instance,
+		sizeof (vl.type_instance));
       else
-	ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s",
-	    data->instance_prefix, temp);
-    }
+      {
+        /* Look for __SUBID__ in the instance prefix. If found,
+         * replace it with the subid value in vl._type_instance. */
+        char *replacement_pos = strstr(data->instance_prefix, "__SUBID__");
+        if (replacement_pos == NULL)
+          ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s",
+		data->instance_prefix, instance_list_ptr->instance);
+        else
+        {
+          int prefix_len = replacement_pos - data->instance_prefix;
+          char prefix[prefix_len + 1];
+          if (prefix_len > 0)
+            sstrncpy(prefix, data->instance_prefix, sizeof(prefix));
+          else
+            prefix[0] = '\0';
+
+          ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%"PRIu32"%s%s",
+		prefix, (uint32_t)subid, replacement_pos + sizeof("__SUBID__") -1,
+		instance_list_ptr->instance);
+        }
+      }
 
     for (i = 0; i < data->values_len; i++)
       vl.values[i] = value_table_ptr[i]->value;
--- a/src/collectd-snmp.pod	2011-03-27 09:35:08.000000000 -0700
+++ b/src/collectd-snmp.pod	2011-04-28 11:34:36.000000000 -0700
@@ -148,6 +148,10 @@ instance of the files. If set, I<String>
 determined by querying the agent. When B<Table> is set to I<false> this option
 has no effect.
 
+The first occurrence I<__SUBID__> within the value is substituted with the
+subid of the table entry. An example of this use would be to include both the
+interface description and the subid in rrds generated for interface.
+
 The C<UPS-MIB> is an example where you need this setting: It has voltages of
 the inlets, outlets and the battery of an UPS. However, it doesn't provide a
 descriptive column for these voltages. In this case having 1, 2,E<nbsp>... as
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd

Reply via email to