Merge pull request #579 from mfournier/libiptc-ldflags
authorPierre-Yves Ritschard <pyr@spootnik.org>
Mon, 28 Jul 2014 20:48:17 +0000 (22:48 +0200)
committerPierre-Yves Ritschard <pyr@spootnik.org>
Mon, 28 Jul 2014 20:48:17 +0000 (22:48 +0200)
link iptables plugin against flags from pkg-config

12 files changed:
contrib/collection3/etc/collection.conf
src/aggregation.c
src/collectd-unixsock.pod
src/collectd.conf.pod
src/exec.c
src/java.c
src/pyvalues.c
src/threshold.c
src/utils_cmd_putnotif.c
src/utils_format_graphite.c
src/utils_vl_lookup.c
src/write_riemann.c

index 5fe4313..3e19bfc 100644 (file)
@@ -7,7 +7,7 @@ GraphWidth 400
   RRDTitle "Apache Traffic"
   RRDVerticalLabel "Bytes/s"
   RRDFormat "%5.1lf%s"
-  Color count 0000ff
+  Color value 0000ff
 </Type>
 <Type apache_requests>
   DataSources value
@@ -15,7 +15,7 @@ GraphWidth 400
   RRDTitle "Apache Traffic"
   RRDVerticalLabel "Requests/s"
   RRDFormat "%5.2lf"
-  Color count 00d000
+  Color value 00d000
 </Type>
 <Type apache_scoreboard>
   Module GenericStacked
@@ -272,7 +272,7 @@ GraphWidth 400
   RRDTitle "Frequency ({type_instance})"
   RRDVerticalLabel "Hertz"
   RRDFormat "%4.1lfHz"
-  Color frequency a000a0
+  Color value a000a0
 </Type>
 <Type humidity>
   DataSources value
@@ -547,7 +547,7 @@ GraphWidth 400
   RRDTitle "Percent ({type_instance})"
   RRDVerticalLabel "Percent"
   RRDFormat "%4.1lf%%"
-  Color percent 0000ff
+  Color value 0000ff
 </Type>
 <Type ping>
   DataSources value
@@ -705,7 +705,7 @@ GraphWidth 400
   RRDTitle "Users ({type_instance}) on {hostname}"
   RRDVerticalLabel "Users"
   RRDFormat "%.1lf"
-  Color users 0000f0
+  Color value 0000f0
 </Type>
 <Type voltage>
   DataSources value
index 0c0f19d..8175c66 100644 (file)
@@ -440,8 +440,7 @@ static int agg_instance_read (agg_instance_t *inst, cdtime_t t) /* {{{ */
 
 /* lookup_class_callback_t for utils_vl_lookup */
 static void *agg_lookup_class_callback ( /* {{{ */
-    __attribute__((unused)) data_set_t const *ds,
-    value_list_t const *vl, void *user_class)
+    data_set_t const *ds, value_list_t const *vl, void *user_class)
 {
   return (agg_instance_create (ds, vl, (aggregation_t *) user_class));
 } /* }}} void *agg_class_callback */
index 40626d3..c572df1 100644 (file)
@@ -13,6 +13,7 @@ collectd-unixsock - Documentation of collectd's C<unixsock plugin>
     SocketFile "/path/to/socket"
     SocketGroup "collectd"
     SocketPerms "0770"
+    DeleteSocket false
   </Plugin>
 
 =head1 DESCRIPTION
index 98b492d..45ec831 100644 (file)
@@ -435,6 +435,8 @@ possibly filtering or messages.
  #   StoreRates false
  #   GraphitePrefix "collectd."
  #   GraphiteEscapeChar "_"
+ #   GraphiteSeparateInstances false
+ #   GraphiteAlwaysAppendDS false
    </Publish>
    
    # Receive values from an AMQP broker
@@ -572,6 +574,19 @@ In I<Graphite> metric name, dots are used as separators between different
 metric parts (host, plugin, type).
 Default is "_" (I<Underscore>).
 
+=item B<GraphiteSeparateInstances> B<true>|B<false>
+
+If set to B<true>, the plugin instance and type instance will be in their own
+path component, for example C<host.cpu.0.cpu.idle>. If set to B<false> (the
+default), the plugin and plugin instance (and likewise the type and type
+instance) are put into one component, for example C<host.cpu-0.cpu-idle>.
+
+=item B<GraphiteAlwaysAppendDS> B<true>|B<false>
+
+If set to 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.
+
 =back
 
 =head2 Plugin C<apache>
@@ -5674,7 +5689,7 @@ instance) are put into one component, for example C<host.cpu-0.cpu-idle>.
 
 =item B<AlwaysAppendDS> B<false>|B<true>
 
-If set the B<true>, append the name of the I<Data Source> (DS) to the "metric"
+If set to 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.
 
index cfd82a3..b9a7365 100644 (file)
@@ -744,8 +744,8 @@ static void *exec_notification_one (void *arg) /* {{{ */
 
   fprintf (fh,
       "Severity: %s\n"
-      "Time: %.3f\n",
-      severity, CDTIME_T_TO_DOUBLE (n->time));
+      "Time: %u\n",
+      severity, (unsigned int)CDTIME_T_TO_TIME_T(n->time));
 
   /* Print the optional fields */
   if (strlen (n->host) > 0)
index b69ca94..ee50355 100644 (file)
@@ -906,7 +906,7 @@ static jobject ctoj_notification (JNIEnv *jvm_env, /* {{{ */
 #undef SET_STRING
 
   /* Set the `time' member. Java stores time in milliseconds. */
-  status = ctoj_long (jvm_env, ((jlong) n->time) * ((jlong) 1000),
+  status = ctoj_long (jvm_env, (jlong) CDTIME_T_TO_MS (n->time),
       c_notification, o_notification, "setTime");
   if (status != 0)
   {
@@ -1306,7 +1306,7 @@ static int jtoc_notification (JNIEnv *jvm_env, notification_t *n, /* {{{ */
     return (-1);
   }
   /* Java measures time in milliseconds. */
-  n->time = (time_t) (tmp_long / ((jlong) 1000));
+  n->time = MS_TO_CDTIME_T(tmp_long);
 
   status = jtoc_int (jvm_env, &tmp_int,
       class_ptr, object_ptr, "getSeverity");
index 307af17..4a658d0 100644 (file)
@@ -767,7 +767,7 @@ static void Values_dealloc(PyObject *self) {
 }
 
 static PyMemberDef Values_members[] = {
-       {"interval", T_INT, offsetof(Values, interval), 0, interval_doc},
+       {"interval", T_DOUBLE, offsetof(Values, interval), 0, interval_doc},
        {"values", T_OBJECT_EX, offsetof(Values, values), 0, values_doc},
        {"meta", T_OBJECT_EX, offsetof(Values, meta), 0, meta_doc},
        {NULL}
index 7df4d61..887dbca 100644 (file)
@@ -942,6 +942,7 @@ static int ut_missing (const value_list_t *vl,
   cdtime_t missing_time;
   char identifier[6 * DATA_MAX_NAME_LEN];
   notification_t n;
+  cdtime_t now;
 
   if (threshold_tree == NULL)
     return (0);
@@ -951,13 +952,15 @@ static int ut_missing (const value_list_t *vl,
   if ((th == NULL) || ((th->flags & UT_FLAG_INTERESTING) == 0))
     return (0);
 
-  missing_time = cdtime () - vl->time;
+  now = cdtime ();
+  missing_time = now - vl->time;
   FORMAT_VL (identifier, sizeof (identifier), vl);
 
   NOTIFICATION_INIT_VL (&n, vl);
   ssnprintf (n.message, sizeof (n.message),
       "%s has not been updated for %.3f seconds.",
       identifier, CDTIME_T_TO_DOUBLE (missing_time));
+  n.time = now;
 
   plugin_dispatch_notification (&n);
 
index 5a9faff..cba08bf 100644 (file)
@@ -49,13 +49,18 @@ static int set_option_severity (notification_t *n, const char *value)
 
 static int set_option_time (notification_t *n, const char *value)
 {
-  time_t tmp;
-  
-  tmp = (time_t) atoi (value);
-  if (tmp <= 0)
+  char *endptr = NULL;
+  double tmp;
+
+  errno = 0;
+  tmp = strtod (value, &endptr);
+  if ((errno != 0)         /* Overflow */
+      || (endptr == value) /* Invalid string */
+      || (endptr == NULL)  /* This should not happen */
+      || (*endptr != 0))   /* Trailing chars */
     return (-1);
 
-  n->time = tmp;
+  n->time = TIME_T_TO_CDTIME_T (tmp);
 
   return (0);
 } /* int set_option_time */
index 8351201..b7d4494 100644 (file)
@@ -29,6 +29,8 @@
 #include "utils_cache.h"
 #include "utils_parse_option.h"
 
+#define GRAPHITE_FORBIDDEN " \t\"\\:!/()\n\r"
+
 /* Utils functions to format data sets in graphite format.
  * Largely taken from write_graphite.c as it remains the same formatting */
 
@@ -169,6 +171,18 @@ static int gr_format_name (char *ret, int ret_len,
     return (0);
 }
 
+static void escape_graphite_string (char *buffer, char escape_char)
+{
+       char *head;
+
+       assert (strchr(GRAPHITE_FORBIDDEN, escape_char) == NULL);
+
+       for (head = buffer + strcspn(buffer, GRAPHITE_FORBIDDEN);
+            *head != '\0';
+            head += strcspn(head, GRAPHITE_FORBIDDEN))
+               *head = escape_char;
+}
+
 int format_graphite (char *buffer, size_t buffer_size,
     data_set_t const *ds, value_list_t const *vl,
     char const *prefix, char const *postfix, char const escape_char,
@@ -204,7 +218,7 @@ int format_graphite (char *buffer, size_t buffer_size,
             return (status);
         }
 
-        escape_string (key, sizeof (key));
+        escape_graphite_string (key, escape_char);
         /* Convert the values to an ASCII representation and put that into
          * `values'. */
         status = gr_format_values (values, sizeof (values), i, ds, vl, rates);
index 722c452..8180d0d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "collectd.h"
 
+#include <pthread.h>
 #include <regex.h>
 
 #include "common.h"
@@ -86,6 +87,7 @@ struct user_obj_s
 
 struct user_class_s
 {
+  pthread_mutex_t lock;
   void *user_class;
   identifier_match_t match;
   user_obj_t *user_obj_list; /* list of user_obj */
@@ -191,6 +193,7 @@ static int lu_copy_ident_to_match (identifier_match_t *match, /* {{{ */
   return (0);
 } /* }}} int lu_copy_ident_to_match */
 
+/* user_class->lock must be held when calling this function */
 static void *lu_create_user_obj (lookup_t *obj, /* {{{ */
     data_set_t const *ds, value_list_t const *vl,
     user_class_t *user_class)
@@ -245,6 +248,7 @@ static void *lu_create_user_obj (lookup_t *obj, /* {{{ */
   return (user_obj);
 } /* }}} void *lu_create_user_obj */
 
+/* user_class->lock must be held when calling this function */
 static user_obj_t *lu_find_user_obj (user_class_t *user_class, /* {{{ */
     value_list_t const *vl)
 {
@@ -294,14 +298,17 @@ static int lu_handle_user_class (lookup_t *obj, /* {{{ */
       || !lu_part_matches (&user_class->match.host, vl->host))
     return (1);
 
+  pthread_mutex_lock (&user_class->lock);
   user_obj = lu_find_user_obj (user_class, vl);
   if (user_obj == NULL)
   {
     /* call lookup_class_callback_t() and insert into the list of user objects. */
     user_obj = lu_create_user_obj (obj, ds, vl, user_class);
+    pthread_mutex_unlock (&user_class->lock);
     if (user_obj == NULL)
       return (-1);
   }
+  pthread_mutex_unlock (&user_class->lock);
 
   status = obj->cb_user_obj (ds, vl,
       user_class->user_class, user_obj->user_obj);
@@ -402,7 +409,7 @@ static int lu_add_by_plugin (by_type_entry_t *by_type, /* {{{ */
   identifier_match_t const *match = &user_class_list->entry.match;
 
   /* Lookup user_class_list from the per-plugin structure. If this is the first
-   * user_class to be added, the blocks return immediately. Otherwise they will
+   * user_class to be added, the block returns immediately. Otherwise they will
    * set "ptr" to non-NULL. */
   if (match->plugin.is_regex)
   {
@@ -487,6 +494,7 @@ static void lu_destroy_user_class_list (lookup_t *obj, /* {{{ */
 
     lu_destroy_user_obj (obj, user_class_list->entry.user_obj_list);
     user_class_list->entry.user_obj_list = NULL;
+    pthread_mutex_destroy (&user_class_list->entry.lock);
 
     sfree (user_class_list);
     user_class_list = next;
@@ -599,6 +607,7 @@ int lookup_add (lookup_t *obj, /* {{{ */
     return (ENOMEM);
   }
   memset (user_class_obj, 0, sizeof (*user_class_obj));
+  pthread_mutex_init (&user_class_obj->entry.lock, /* attr = */ NULL);
   user_class_obj->entry.user_class = user_class;
   lu_copy_ident_to_match (&user_class_obj->entry.match, ident, group_by);
   user_class_obj->entry.user_obj_list = NULL;
index fdd160b..b558b06 100644 (file)
@@ -84,7 +84,7 @@ static void riemann_event_protobuf_free (Event *event) /* {{{ */
        sfree (event);
 } /* }}} void riemann_event_protobuf_free */
 
-static void riemann_msg_protobuf_free (Msg *msg) /* {{{ */
+static void riemann_msg_protobuf_free(Msg *msg) /* {{{ */
 {
        size_t i;
 
@@ -104,8 +104,7 @@ static void riemann_msg_protobuf_free (Msg *msg) /* {{{ */
 } /* }}} void riemann_msg_protobuf_free */
 
 /* host->lock must be held when calling this function. */
-static int
-riemann_connect(struct riemann_host *host)
+static int riemann_connect(struct riemann_host *host) /* {{{ */
 {
        int                      e;
        struct addrinfo         *ai, *res, hints;
@@ -160,11 +159,10 @@ riemann_connect(struct riemann_host *host)
                return -1;
        }
        return 0;
-}
+} /* }}} int riemann_connect */
 
 /* host->lock must be held when calling this function. */
-static int
-riemann_disconnect (struct riemann_host *host)
+static int riemann_disconnect (struct riemann_host *host) /* {{{ */
 {
        if ((host->flags & F_CONNECT) == 0)
                return (0);
@@ -174,17 +172,15 @@ riemann_disconnect (struct riemann_host *host)
        host->flags &= ~F_CONNECT;
 
        return (0);
-}
+} /* }}} int riemann_disconnect */
 
-static inline int
-riemann_send_msg(struct riemann_host *host, const Msg *msg)
+static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ */
 {
        int status = 0;
        u_char *buffer = NULL;
        size_t  buffer_len;
 
        status = riemann_connect (host);
-
        if (status != 0)
                return status;
 
@@ -194,12 +190,10 @@ riemann_send_msg(struct riemann_host *host, const Msg *msg)
                buffer_len += 4;
 
        buffer = malloc (buffer_len);
-
        if (buffer == NULL) {
                ERROR ("write_riemann plugin: malloc failed.");
                return ENOMEM;
        }
-
        memset (buffer, 0, buffer_len);
 
        if (host->use_tcp)
@@ -214,26 +208,22 @@ riemann_send_msg(struct riemann_host *host, const Msg *msg)
        }
 
        status = (int) swrite (host->s, buffer, buffer_len);
-
        if (status != 0)
        {
                char errbuf[1024];
-
                ERROR ("write_riemann plugin: Sending to Riemann at %s:%s failed: %s",
                                (host->node != NULL) ? host->node : RIEMANN_HOST,
                                (host->service != NULL) ? host->service : RIEMANN_PORT,
                                sstrerror (errno, errbuf, sizeof (errbuf)));
-
                sfree (buffer);
                return -1;
        }
 
        sfree (buffer);
        return 0;
-}
+} /* }}} int riemann_send_msg */
 
-static inline int
-riemann_recv_ack(struct riemann_host *host)
+static int riemann_recv_ack(struct riemann_host *host) /* {{{ */
 {
        int status = 0;
        Msg *msg = NULL;
@@ -273,21 +263,19 @@ riemann_recv_ack(struct riemann_host *host)
 
        msg__free_unpacked (msg, NULL);
        return 0;
-}
+} /* }}} int riemann_recv_ack */
 
 /**
  * Function to send messages (Msg) to riemann.
  *
  * Acquires the host lock, disconnects on errors.
  */
-static int
-riemann_send(struct riemann_host *host, Msg const *msg)
+static int riemann_send(struct riemann_host *host, Msg const *msg) /* {{{ */
 {
        int status = 0;
        pthread_mutex_lock (&host->lock);
 
        status = riemann_send_msg(host, msg);
-
        if (status != 0) {
                riemann_disconnect (host);
                pthread_mutex_unlock (&host->lock);
@@ -311,14 +299,14 @@ riemann_send(struct riemann_host *host, Msg const *msg)
 
        pthread_mutex_unlock (&host->lock);
        return 0;
-}
+} /* }}} int riemann_send */
 
 static int riemann_event_add_tag (Event *event, char const *tag) /* {{{ */
 {
        return (strarray_add (&event->tags, &event->n_tags, tag));
 } /* }}} int riemann_event_add_tag */
 
-static int riemann_event_add_attribute (Event *event, /* {{{ */
+static int riemann_event_add_attribute(Event *event, /* {{{ */
                char const *key, char const *value)
 {
        Attribute **new_attributes;
@@ -351,7 +339,7 @@ static int riemann_event_add_attribute (Event *event, /* {{{ */
        return (0);
 } /* }}} int riemann_event_add_attribute */
 
-static Msg *riemann_notification_to_protobuf (struct riemann_host *host, /* {{{ */
+static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ */
                notification_t const *n)
 {
        Msg *msg;
@@ -445,7 +433,7 @@ static Msg *riemann_notification_to_protobuf (struct riemann_host *host, /* {{{
        return (msg);
 } /* }}} Msg *riemann_notification_to_protobuf */
 
-static Event *riemann_value_to_protobuf (struct riemann_host const *host, /* {{{ */
+static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
                data_set_t const *ds,
                value_list_t const *vl, size_t index,
                gauge_t const *rates)
@@ -543,7 +531,7 @@ static Event *riemann_value_to_protobuf (struct riemann_host const *host, /* {{{
        return (event);
 } /* }}} Event *riemann_value_to_protobuf */
 
-static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
+static Msg *riemann_value_list_to_protobuf(struct riemann_host const *host, /* {{{ */
                data_set_t const *ds,
                value_list_t const *vl)
 {
@@ -598,8 +586,7 @@ static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /*
        return (msg);
 } /* }}} Msg *riemann_value_list_to_protobuf */
 
-static int
-riemann_notification(const notification_t *n, user_data_t *ud)
+static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
 {
        int                      status;
        struct riemann_host     *host = ud->data;
@@ -618,8 +605,7 @@ riemann_notification(const notification_t *n, user_data_t *ud)
        return (status);
 } /* }}} int riemann_notification */
 
-static int
-riemann_write(const data_set_t *ds,
+static int riemann_write(const data_set_t *ds, /* {{{ */
              const value_list_t *vl,
              user_data_t *ud)
 {
@@ -638,10 +624,9 @@ riemann_write(const data_set_t *ds,
 
        riemann_msg_protobuf_free (msg);
        return status;
-}
+} /* }}} int riemann_write */
 
-static void
-riemann_free(void *p)
+static void riemann_free(void *p) /* {{{ */
 {
        struct riemann_host     *host = p;
 
@@ -662,10 +647,9 @@ riemann_free(void *p)
        sfree(host->service);
        pthread_mutex_destroy (&host->lock);
        sfree(host);
-}
+} /* }}} void riemann_free */
 
-static int
-riemann_config_node(oconfig_item_t *ci)
+static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
 {
        struct riemann_host     *host = NULL;
        int                      status = 0;
@@ -793,10 +777,9 @@ riemann_config_node(oconfig_item_t *ci)
        pthread_mutex_unlock (&host->lock);
 
        return status;
-}
+} /* }}} int riemann_config_node */
 
-static int
-riemann_config(oconfig_item_t *ci)
+static int riemann_config(oconfig_item_t *ci) /* {{{ */
 {
        int              i;
        oconfig_item_t  *child;
@@ -823,10 +806,9 @@ riemann_config(oconfig_item_t *ci)
                }
        }
        return (0);
-}
+} /* }}} int riemann_config */
 
-void
-module_register(void)
+void module_register(void)
 {
        plugin_register_complex_config ("write_riemann", riemann_config);
 }