[collectd] [PATCH] Add support for lowercaseing identifiers

Gavin Mogan GavinM at airg.com
Wed Mar 27 05:24:34 CET 2013


From: Gavin <gavinm at airg.com>


Signed-off-by: Gavin <gavinm at airg.com>
---
 src/collectd.conf.pod       |    6 ++++++
 src/utils_format_graphite.c |   13 +++++++++++++
 src/utils_format_graphite.h |    1 +
 src/write_graphite.c        |    7 +++++++
 4 files changed, 27 insertions(+)

diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 8606d3e..6e68792 100644
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -5636,6 +5636,12 @@ If set the B<true>, append the name of the I<Data Source> (DS) to the "metric"
 identifier. If set to B<false> (the default), this is only done when there is
 more than one DS.
 
+=item B<LowercaseIdentifier> B<false>|B<true>
+
+If set the B<true>, all identifiers will be lower cased before sending them off 
+to carbon/graphite. If set to B<false>(the default), the identifier is left
+untouched.
+
 =back
 
 =head2 Plugin C<write_mongodb>
diff --git a/src/utils_format_graphite.c b/src/utils_format_graphite.c
index 8351201..5600938 100644
--- a/src/utils_format_graphite.c
+++ b/src/utils_format_graphite.c
@@ -166,6 +166,19 @@ static int gr_format_name (char *ret, int ret_len,
         ssnprintf (ret, ret_len, "%s%s%s.%s.%s",
             prefix, n_host, postfix, tmp_plugin, tmp_type);
 
+    if (flags & GRAPHITE_LOWERCASE_IDENT)
+    {
+        int i;
+        for (i = 0; i < ret_len; i++)
+        {
+            if (ret[i] == '\0')
+                break;
+            else if (isalnum (ret[i]))
+                ret[i] = (char) tolower (ret[i]);
+        }
+    }
+
+
     return (0);
 }
 
diff --git a/src/utils_format_graphite.h b/src/utils_format_graphite.h
index 398defb..15ece86 100644
--- a/src/utils_format_graphite.h
+++ b/src/utils_format_graphite.h
@@ -28,6 +28,7 @@
 #define GRAPHITE_STORE_RATES        0x01
 #define GRAPHITE_SEPARATE_INSTANCES 0x02
 #define GRAPHITE_ALWAYS_APPEND_DS   0x04
+#define GRAPHITE_LOWERCASE_IDENT    0x08
 
 int format_graphite (char *buffer,
     size_t buffer_size, const data_set_t *ds,
diff --git a/src/write_graphite.c b/src/write_graphite.c
index 949a842..626339f 100644
--- a/src/write_graphite.c
+++ b/src/write_graphite.c
@@ -56,6 +56,10 @@
 #include <sys/socket.h>
 #include <netdb.h>
 
+#if HAVE_CTYPE_H
+#  include <ctype.h>
+#endif
+
 #ifndef WG_DEFAULT_NODE
 # define WG_DEFAULT_NODE "localhost"
 #endif
@@ -484,6 +488,9 @@ static int wg_config_node (oconfig_item_t *ci)
                     GRAPHITE_ALWAYS_APPEND_DS);
         else if (strcasecmp ("EscapeCharacter", child->key) == 0)
             config_set_char (&cb->escape_char, child);
+        else if (strcasecmp ("LowercaseIdentifier", child->key) == 0)
+            cf_util_get_flag (child, &cb->format_flags,
+                    GRAPHITE_LOWERCASE_IDENT);
         else
         {
             ERROR ("write_graphite plugin: Invalid configuration "
-- 
1.7.10.4



More information about the collectd mailing list