Code

Merge remote-tracking branch 'github-tokkee/sh/netapp'
authorFlorian Forster <octo@collectd.org>
Tue, 29 Jan 2013 09:40:24 +0000 (10:40 +0100)
committerFlorian Forster <octo@collectd.org>
Tue, 29 Jan 2013 09:40:24 +0000 (10:40 +0100)
src/collectd.conf.in
src/collectd.conf.pod
src/postgresql.c
src/write_graphite.c
src/write_riemann.c

index 9f0390e4451623693bd3a5753861b87c59428d1d..8744b21afcaf437020d045d0eb26ca95bc69fca3 100644 (file)
 #</Plugin>
 
 #<Plugin write_graphite>
-#  <Carbon>
+#  <Node "example">
 #    Host "localhost"
 #    Port "2003"
 #    Prefix "collectd"
 #    Postfix "collectd"
-#    StoreRates false
+#    StoreRates true
 #    AlwaysAppendDS false
 #    EscapeCharacter "_"
-#  </Carbon>
+#  </Node>
 #</Plugin>
 
 #<Plugin write_http>
 #      <Node "example">
 #              Host "localhost"
 #              Port 5555
+#              Protocol UDP
 #              StoreRates true
 #              AlwaysAppendDS false
 #      </Node>
index 023c376d2c652dfc94652e3fb68b14682ef12dce..70bc997d650c7993d8c3526d82c73bdc93544eb2 100644 (file)
@@ -5452,13 +5452,16 @@ minimize the number of network packets.
 Synopsis:
 
  <Plugin write_graphite>
-   <Carbon>
+   <Node "example">
      Host "localhost"
      Port "2003"
      Prefix "collectd"
-   </Carbon>
+   </Node>
  </Plugin>
 
+The configuration consists of one or more E<lt>B<Node>E<nbsp>I<Name>E<gt>
+blocks. Inside the B<Node> blocks, the following options are recognized:
+
 =over 4
 
 =item B<Host> I<Address>
@@ -5626,7 +5629,9 @@ Synopsis:
    <Node "example">
      Host "localhost"
      Port "5555"
-     StoreRates false
+     Protocol UDP
+     StoreRates true
+     AlwaysAppendDS false
      Delay 10
    </Node>
    Tag "foobar"
@@ -5653,7 +5658,12 @@ Hostname or address to connect to. Defaults to C<localhost>.
 
 Service name or port number to connect to. Defaults to C<5555>.
 
-=item B<StoreRates> B<false>|B<true>
+=item B<Protocol> B<UDP>|B<TCP>
+
+Specify the protocol to use when communicating with I<Riemann>. Defaults to
+B<UDP>.
+
+=item B<StoreRates> B<true>|B<false>
 
 If set to B<true> (the default), convert counter values to rates. If set to
 B<false> counter values are stored as is, i.e. as an increasing integer number.
index 6c9ab44e8b3379aff58dd9b0b7a4295e6b74876c..0a646391fcc7acf8affe444bb50387926184ffd3 100644 (file)
@@ -371,9 +371,6 @@ static int c_psql_check_connection (c_psql_database_t *db)
                c_psql_connect (db);
        }
 
-       /* "ping" */
-       PQclear (PQexec (db->conn, "SELECT 42;"));
-
        if (CONNECTION_OK != PQstatus (db->conn)) {
                PQreset (db->conn);
 
@@ -514,6 +511,12 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q,
        if (PGRES_TUPLES_OK != PQresultStatus (res)) {
                pthread_mutex_lock (&db->db_lock);
 
+               if ((CONNECTION_OK != PQstatus (db->conn))
+                               && (0 == c_psql_check_connection (db))) {
+                       PQclear (res);
+                       return c_psql_exec_query (db, q, prep_area);
+               }
+
                log_err ("Failed to execute SQL query: %s",
                                PQerrorMessage (db->conn));
                log_info ("SQL query was: %s",
index 2ae30efe2ca179b0fd13cfafe5914f5a031b14ff..1d504100008e5ccebbad3e5dba3fa1d26f714d03 100644 (file)
@@ -79,6 +79,8 @@ struct wg_callback
 {
     int      sock_fd;
 
+    char    *name;
+
     char    *node;
     char    *service;
     char    *prefix;
@@ -244,6 +246,7 @@ static void wg_callback_free (void *data)
     close(cb->sock_fd);
     cb->sock_fd = -1;
 
+    sfree(cb->name);
     sfree(cb->node);
     sfree(cb->service);
     sfree(cb->prefix);
@@ -414,7 +417,7 @@ static int config_set_char (char *dest,
     return (0);
 }
 
-static int wg_config_carbon (oconfig_item_t *ci)
+static int wg_config_node (oconfig_item_t *ci)
 {
     struct wg_callback *cb;
     user_data_t user_data;
@@ -429,6 +432,7 @@ static int wg_config_carbon (oconfig_item_t *ci)
     }
     memset (cb, 0, sizeof (*cb));
     cb->sock_fd = -1;
+    cb->name = NULL;
     cb->node = NULL;
     cb->service = NULL;
     cb->prefix = NULL;
@@ -436,6 +440,17 @@ static int wg_config_carbon (oconfig_item_t *ci)
     cb->escape_char = WG_DEFAULT_ESCAPE;
     cb->store_rates = 1;
 
+    /* FIXME: Legacy configuration syntax. */
+    if (strcasecmp ("Carbon", ci->key) != 0)
+    {
+        int status = cf_util_get_string (ci, &cb->name);
+        if (status != 0)
+        {
+            wg_callback_free (cb);
+            return (status);
+        }
+    }
+
     pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
 
     for (i = 0; i < ci->children_num; i++)
@@ -465,9 +480,14 @@ static int wg_config_carbon (oconfig_item_t *ci)
         }
     }
 
-    ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s/%s",
-            cb->node != NULL ? cb->node : WG_DEFAULT_NODE,
-            cb->service != NULL ? cb->service : WG_DEFAULT_SERVICE);
+    /* FIXME: Legacy configuration syntax. */
+    if (cb->name == NULL)
+        ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s/%s",
+                cb->node != NULL ? cb->node : WG_DEFAULT_NODE,
+                cb->service != NULL ? cb->service : WG_DEFAULT_SERVICE);
+    else
+        ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s",
+                cb->name);
 
     memset (&user_data, 0, sizeof (user_data));
     user_data.data = cb;
@@ -488,8 +508,11 @@ static int wg_config (oconfig_item_t *ci)
     {
         oconfig_item_t *child = ci->children + i;
 
-        if (strcasecmp ("Carbon", child->key) == 0)
-            wg_config_carbon (child);
+        if (strcasecmp ("Node", child->key) == 0)
+            wg_config_node (child);
+        /* FIXME: Remove this legacy mode in version 6. */
+        else if (strcasecmp ("Carbon", child->key) == 0)
+            wg_config_node (child);
         else
         {
             ERROR ("write_graphite plugin: Invalid configuration "
index 62d75f3662c6ef117f9cd504d5084a2aaecd740c..df0c373352d696ebd8b6ff7490f14f1c715862f0 100644 (file)
@@ -47,6 +47,7 @@ struct riemann_host {
        _Bool                    always_append_ds;
        char                    *node;
        char                    *service;
+       _Bool                    use_tcp;
        int                      s;
 
        int                      reference_count;
@@ -118,6 +119,9 @@ riemann_send(struct riemann_host *host, Msg const *msg)
        }
 
        buffer_len = msg__get_packed_size(msg);
+       if (host->use_tcp)
+               buffer_len += 4;
+
        buffer = malloc (buffer_len);
        if (buffer == NULL) {
                pthread_mutex_unlock (&host->lock);
@@ -126,7 +130,16 @@ riemann_send(struct riemann_host *host, Msg const *msg)
        }
        memset (buffer, 0, buffer_len);
 
-       msg__pack(msg, buffer);
+       if (host->use_tcp)
+       {
+               uint32_t length = htonl ((uint32_t) (buffer_len - 4));
+               memcpy (buffer, &length, 4);
+               msg__pack(msg, buffer + 4);
+       }
+       else
+       {
+               msg__pack(msg, buffer);
+       }
 
        status = (int) swrite (host->s, buffer, buffer_len);
        if (status != 0)
@@ -460,7 +473,7 @@ riemann_connect(struct riemann_host *host)
        memset(&hints, 0, sizeof(hints));
        memset(&service, 0, sizeof(service));
        hints.ai_family = AF_UNSPEC;
-       hints.ai_socktype = SOCK_DGRAM;
+       hints.ai_socktype = host->use_tcp ? SOCK_STREAM : SOCK_DGRAM;
 #ifdef AI_ADDRCONFIG
        hints.ai_flags |= AI_ADDRCONFIG;
 #endif
@@ -562,6 +575,7 @@ riemann_config_node(oconfig_item_t *ci)
        host->service = NULL;
        host->store_rates = 1;
        host->always_append_ds = 0;
+       host->use_tcp = 0;
 
        status = cf_util_get_string (ci, &host->name);
        if (status != 0) {
@@ -590,6 +604,28 @@ riemann_config_node(oconfig_item_t *ci)
                                                "option.");
                                break;
                        }
+               } else if (strcasecmp ("Protocol", child->key) == 0) {
+                       char tmp[16];
+                       status = cf_util_get_string_buffer (child,
+                                       tmp, sizeof (tmp));
+                       if (status != 0)
+                       {
+                               ERROR ("write_riemann plugin: cf_util_get_"
+                                               "string_buffer failed with "
+                                               "status %i.", status);
+                               break;
+                       }
+
+                       if (strcasecmp ("UDP", tmp) == 0)
+                               host->use_tcp = 0;
+                       else if (strcasecmp ("TCP", tmp) == 0)
+                               host->use_tcp = 1;
+                       else
+                               WARNING ("write_riemann plugin: The value "
+                                               "\"%s\" is not valid for the "
+                                               "\"Protocol\" option. Use "
+                                               "either \"UDP\" or \"TCP\".",
+                                               tmp);
                } else if (strcasecmp ("StoreRates", child->key) == 0) {
                        status = cf_util_get_boolean (child, &host->store_rates);
                        if (status != 0)