Merge remote-tracking branches 'github/pr/392' and 'github/pr/399' into jr/json
authorFlorian Forster <octo@collectd.org>
Sun, 18 Aug 2013 07:04:45 +0000 (09:04 +0200)
committerFlorian Forster <octo@collectd.org>
Sun, 18 Aug 2013 07:04:45 +0000 (09:04 +0200)
.gitignore
clean.sh
src/collectd.conf.pod
src/curl_json.c
src/statsd.c
src/types.db
src/utils_latency.c
src/utils_latency.h
src/varnish.c

index 6e87aaf..7c7c848 100644 (file)
@@ -33,11 +33,12 @@ src/stamp-h1
 .libs/
 src/collectd
 src/collectd-nagios
+src/collectd-tg
 src/collectdctl
 src/collectdmon
 src/*.1
 src/*.5
-src/libcollectdclient/lcc_features.h
+src/libcollectdclient/collectd/lcc_features.h
 
 # patch stuff
 *.rej
index 9defb05..46e8c29 100755 (executable)
--- a/clean.sh
+++ b/clean.sh
@@ -21,6 +21,7 @@ true \
 && rm -f Makefile \
 && rm -f Makefile.in \
 && rm -f missing \
+&& rm -f INSTALL \
 && rm -f -r src/.deps \
 && rm -f -r src/.libs \
 && rm -f src/*.o \
@@ -28,6 +29,11 @@ true \
 && rm -f src/*.lo \
 && rm -f src/collectd \
 && rm -f src/collectd.1 \
+&& rm -f src/collectd.conf \
+&& rm -f src/collectdctl \
+&& rm -f src/collectd-tg \
+&& rm -f src/collectd-nagios \
+&& rm -f src/collectdmon \
 && rm -f src/config.h \
 && rm -f src/config.h.in \
 && rm -f src/config.h.in~ \
@@ -35,6 +41,18 @@ true \
 && rm -f src/Makefile.in \
 && rm -f src/stamp-h1 \
 && rm -f src/stamp-h1.in \
+&& rm -f src/*.pb-c.c \
+&& rm -f src/*.pb-c.h \
+&& rm -f src/Makefile.in \
+&& rm -f src/liboconfig/*.o \
+&& rm -f src/liboconfig/*.la \
+&& rm -f src/liboconfig/*.lo \
+&& rm -f -r src/liboconfig/.libs \
+&& rm -f -r src/liboconfig/Makefile \
+&& rm -f -r src/liboconfig/Makefile.in \
+&& rm -f -r src/liboconfig/parser.c \
+&& rm -f -r src/liboconfig/parser.h \
+&& rm -f -r src/liboconfig/scanner.c \
 && rm -f -r src/libping/.libs \
 && rm -f src/libping/*.o \
 && rm -f src/libping/*.la \
@@ -48,5 +66,17 @@ true \
 && rm -f src/libcollectdclient/*.o \
 && rm -f src/libcollectdclient/*.la \
 && rm -f src/libcollectdclient/*.lo \
+&& rm -f src/libcollectdclient/Makefile \
+&& rm -f src/libcollectdclient/Makefile.in \
+&& rm -f src/libcollectdclient/collectd/lcc_features.h \
+&& rm -f src/libcollectdclient/libcollectdclient.pc \
+&& rm -f bindings/Makefile \
+&& rm -f bindings/Makefile.in \
+&& rm -f -r bindings/java/.libs \
+&& rm -f bindings/java/Makefile \
+&& rm -f bindings/java/Makefile.in \
+&& rm -f bindings/java/java-build-stamp \
+&& rm -f bindings/java/org/collectd/api/*.class \
+&& rm -f bindings/java/org/collectd/java/*.class \
 && rm -f bindings/.perl-directory-stamp \
 && rm -f -r bindings/buildperl
index 6158cb7..b026b5a 100644 (file)
@@ -1125,6 +1125,11 @@ The B<Key> string argument must be in a path format, which is used to collect a
 value from a JSON map object. If a path element of B<Key> is the
 I<*>E<nbsp>wildcard, the values for all keys will be collectd.
 
+The B<Key> string argument must be in a path format. Each component is
+used to match the key from a JSON map or the index of an JSON
+array. If a path component of a B<Key> is a I<*>E<nbsp>wildcard, the
+values for all map keys or array indices will be collectd.
+
 The following options are valid within B<URL> blocks:
 
 =over 4
index 594e755..0b3e0e6 100644 (file)
@@ -89,6 +89,8 @@ struct cj_s /* {{{ */
       c_avl_tree_t *tree;
       cj_key_t *key;
     };
+    _Bool in_array;
+    int index;
     char name[DATA_MAX_NAME_LEN];
   } state[YAJL_MAX_DEPTH];
 };
@@ -173,10 +175,41 @@ static int cj_get_type (cj_key_t *key)
   return ds->ds[0].type;
 }
 
+static int cj_cb_map_key (void *ctx, const unsigned char *val,
+    yajl_len_t len);
+
+static void cj_cb_inc_array_index (void * ctx, _Bool ignore)
+{
+  cj_t *db = (cj_t *)ctx;
+
+  if (db->state[db->depth].in_array) {
+    if (ignore)
+      db->state[db->depth].index++;
+    else {
+      char name[DATA_MAX_NAME_LEN];
+      cj_cb_map_key (ctx, (unsigned char *)name,
+                     ssnprintf (name, sizeof (name),
+                                "%d", db->state[db->depth].index++));
+    }
+  }
+}
+
 /* yajl callbacks */
 #define CJ_CB_ABORT    0
 #define CJ_CB_CONTINUE 1
 
+static int cj_cb_boolean (void * ctx, int boolVal)
+{
+  cj_cb_inc_array_index (ctx, 1);
+  return (CJ_CB_CONTINUE);
+}
+
+static int cj_cb_null (void * ctx)
+{
+  cj_cb_inc_array_index (ctx, 1);
+  return (CJ_CB_CONTINUE);
+}
+
 /* "number" may not be null terminated, so copy it into a buffer before
  * parsing. */
 static int cj_cb_number (void *ctx,
@@ -190,8 +223,15 @@ static int cj_cb_number (void *ctx,
   int type;
   int status;
 
-  if ((key == NULL) || !CJ_IS_KEY (key))
+  if ((key == NULL) || !CJ_IS_KEY (key)) {
+    if (key != NULL)
+      NOTICE ("curl_json plugin: Found \"%.*s\", but the configuration expects"
+              " a map.", (int)number_len > number_len ? 0 : (int)number_len,
+              number);
+    cj_cb_inc_array_index (ctx, 1);
     return (CJ_CB_CONTINUE);
+  } else
+    cj_cb_inc_array_index (ctx, 0);
 
   memcpy (buffer, number, number_len);
   buffer[sizeof (buffer) - 1] = 0;
@@ -239,24 +279,6 @@ static int cj_cb_map_key (void *ctx, const unsigned char *val,
 static int cj_cb_string (void *ctx, const unsigned char *val,
     yajl_len_t len)
 {
-  cj_t *db = (cj_t *)ctx;
-  char str[len + 1];
-
-  /* Create a null-terminated version of the string. */
-  memcpy (str, val, len);
-  str[len] = 0;
-
-  /* No configuration for this string -> simply return. */
-  if (db->state[db->depth].key == NULL)
-    return (CJ_CB_CONTINUE);
-
-  if (!CJ_IS_KEY (db->state[db->depth].key))
-  {
-    NOTICE ("curl_json plugin: Found string \"%s\", but the configuration "
-        "expects a map here.", str);
-    return (CJ_CB_CONTINUE);
-  }
-
   /* Handle the string as if it was a number. */
   return (cj_cb_number (ctx, (const char *) val, len));
 } /* int cj_cb_string */
@@ -283,6 +305,7 @@ static int cj_cb_end (void *ctx)
 
 static int cj_cb_start_map (void *ctx)
 {
+  cj_cb_inc_array_index (ctx, 0);
   return cj_cb_start (ctx);
 }
 
@@ -293,17 +316,25 @@ static int cj_cb_end_map (void *ctx)
 
 static int cj_cb_start_array (void * ctx)
 {
+  cj_t *db = (cj_t *)ctx;
+  cj_cb_inc_array_index (ctx, 0);
+  if (db->depth+1 < YAJL_MAX_DEPTH) {
+    db->state[db->depth+1].in_array = 1;
+    db->state[db->depth+1].index = 0;
+  }
   return cj_cb_start (ctx);
 }
 
 static int cj_cb_end_array (void * ctx)
 {
+  cj_t *db = (cj_t *)ctx;
+  db->state[db->depth].in_array = 0;
   return cj_cb_end (ctx);
 }
 
 static yajl_callbacks ycallbacks = {
-  NULL, /* null */
-  NULL, /* boolean */
+  cj_cb_null, /* null */
+  cj_cb_boolean, /* boolean */
   NULL, /* integer */
   NULL, /* double */
   cj_cb_number,
index 5af3483..72a7779 100644 (file)
@@ -79,6 +79,11 @@ static _Bool conf_delete_sets     = 0;
 static double *conf_timer_percentile = NULL;
 static size_t  conf_timer_percentile_num = 0;
 
+static _Bool conf_timer_lower     = 0;
+static _Bool conf_timer_upper     = 0;
+static _Bool conf_timer_sum       = 0;
+static _Bool conf_timer_count     = 0;
+
 /* Must hold metrics_lock when calling this function. */
 static statsd_metric_t *statsd_metric_lookup_unsafe (char const *name, /* {{{ */
     metric_type_t type)
@@ -625,6 +630,14 @@ static int statsd_config (oconfig_item_t *ci) /* {{{ */
       cf_util_get_boolean (child, &conf_delete_gauges);
     else if (strcasecmp ("DeleteSets", child->key) == 0)
       cf_util_get_boolean (child, &conf_delete_sets);
+    else if (strcasecmp ("TimerLower", child->key) == 0)
+      cf_util_get_boolean (child, &conf_timer_lower);
+    else if (strcasecmp ("TimerUpper", child->key) == 0)
+      cf_util_get_boolean (child, &conf_timer_upper);
+    else if (strcasecmp ("TimerSum", child->key) == 0)
+      cf_util_get_boolean (child, &conf_timer_sum);
+    else if (strcasecmp ("TimerCount", child->key) == 0)
+      cf_util_get_boolean (child, &conf_timer_count);
     else if (strcasecmp ("TimerPercentile", child->key) == 0)
       statsd_config_timer_percentile (child);
     else
@@ -726,6 +739,30 @@ static int statsd_metric_submit_unsafe (char const *name, /* {{{ */
         latency_counter_get_average (metric->latency));
     plugin_dispatch_values (&vl);
 
+    if (conf_timer_lower) {
+      ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+          "%s-lower", name);
+      values[0].gauge = CDTIME_T_TO_DOUBLE (
+          latency_counter_get_min (metric->latency));
+      plugin_dispatch_values (&vl);
+    }
+
+    if (conf_timer_upper) {
+      ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+          "%s-upper", name);
+      values[0].gauge = CDTIME_T_TO_DOUBLE (
+          latency_counter_get_max (metric->latency));
+      plugin_dispatch_values (&vl);
+    }
+
+    if (conf_timer_sum) {
+      ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+          "%s-sum", name);
+      values[0].gauge = CDTIME_T_TO_DOUBLE (
+          latency_counter_get_sum (metric->latency));
+      plugin_dispatch_values (&vl);
+    }
+
     for (i = 0; i < conf_timer_percentile_num; i++)
     {
       ssnprintf (vl.type_instance, sizeof (vl.type_instance),
@@ -736,6 +773,16 @@ static int statsd_metric_submit_unsafe (char const *name, /* {{{ */
       plugin_dispatch_values (&vl);
     }
 
+    /* Keep this at the end, since vl.type is set to "gauge" here. The
+     * vl.type's above are implicitly set to "latency". */
+    if (conf_timer_count) {
+      sstrncpy (vl.type, "gauge", sizeof (vl.type));
+      ssnprintf (vl.type_instance, sizeof (vl.type_instance),
+          "%s-count", name);
+      values[0].gauge = latency_counter_get_num (metric->latency);
+      plugin_dispatch_values (&vl);
+    }
+
     latency_counter_reset (metric->latency);
     return (0);
   }
index 723b477..3a5e207 100644 (file)
@@ -87,7 +87,7 @@ io_packets            rx:DERIVE:0:U, tx:DERIVE:0:U
 ipt_bytes              value:DERIVE:0:U
 ipt_packets            value:DERIVE:0:U
 irq                    value:DERIVE:0:U
-latency                        value:GAUGE:0:65535
+latency                        value:GAUGE:0:U
 links                  value:GAUGE:0:U
 load                   shortterm:GAUGE:0:5000, midterm:GAUGE:0:5000, longterm:GAUGE:0:5000
 md_disks               value:GAUGE:0:U
index 01c8b5c..94da211 100644 (file)
@@ -110,6 +110,20 @@ cdtime_t latency_counter_get_max (latency_counter_t *lc) /* {{{ */
   return (lc->max);
 } /* }}} cdtime_t latency_counter_get_max */
 
+cdtime_t latency_counter_get_sum (latency_counter_t *lc) /* {{{ */
+{
+  if (lc == NULL)
+    return (0);
+  return (lc->sum);
+} /* }}} cdtime_t latency_counter_get_sum */
+
+size_t latency_counter_get_num (latency_counter_t *lc) /* {{{ */
+{
+  if (lc == NULL)
+    return (0);
+  return (lc->num);
+} /* }}} size_t latency_counter_get_num */
+
 cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */
 {
   double average;
index 3da2308..3787c77 100644 (file)
@@ -38,6 +38,8 @@ void latency_counter_reset (latency_counter_t *lc);
 
 cdtime_t latency_counter_get_min (latency_counter_t *lc);
 cdtime_t latency_counter_get_max (latency_counter_t *lc);
+cdtime_t latency_counter_get_sum (latency_counter_t *lc);
+size_t   latency_counter_get_num (latency_counter_t *lc);
 cdtime_t latency_counter_get_average (latency_counter_t *lc);
 cdtime_t latency_counter_get_percentile (latency_counter_t *lc,
     double percent);
index e2ced0e..3a8dddd 100644 (file)
@@ -67,7 +67,9 @@ struct user_config_s {
 #endif
        _Bool collect_struct;
        _Bool collect_totals;
+#ifdef HAVE_VARNISH_V3
        _Bool collect_uptime;
+#endif
        _Bool collect_vcl;
        _Bool collect_workers;
 };
@@ -381,10 +383,12 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess",      stats->n_sess);
                /* N struct object         */
                varnish_submit_gauge (conf->instance, "struct", "objects", "object",             stats->n_object);
+#ifdef HAVE_VARNISH_V3
                /* N unresurrected objects */
                varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject",      stats->n_vampireobject);
                /* N struct objectcore     */
                varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore",         stats->n_objectcore);
+#endif
                /* N struct objecthead     */
                varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead",         stats->n_objecthead);
 #ifdef HAVE_VARNISH_V2
@@ -417,11 +421,13 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes",   stats->s_bodybytes);
        }
 
+#ifdef HAVE_VARNISH_V3
        if (conf->collect_uptime)
        {
                /* Client uptime */
                varnish_submit_gauge (conf->instance, "uptime", "uptime", "client_uptime", stats->uptime);
        }
+#endif
 
        if (conf->collect_vcl)
        {
@@ -569,7 +575,9 @@ static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
        conf->collect_sms         = 0;
        conf->collect_struct      = 0;
        conf->collect_totals      = 0;
+#ifdef HAVE_VARNISH_V3
        conf->collect_uptime      = 0;
+#endif
        conf->collect_vcl         = 0;
        conf->collect_workers     = 0;
 
@@ -691,8 +699,10 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
                        cf_util_get_boolean (child, &conf->collect_struct);
                else if (strcasecmp ("CollectTotals", child->key) == 0)
                        cf_util_get_boolean (child, &conf->collect_totals);
+#ifdef HAVE_VARNISH_V3
                else if (strcasecmp ("CollectUptime", child->key) == 0)
                        cf_util_get_boolean (child, &conf->collect_uptime);
+#endif
                else if (strcasecmp ("CollectVCL", child->key) == 0)
                        cf_util_get_boolean (child, &conf->collect_vcl);
                else if (strcasecmp ("CollectWorkers", child->key) == 0)
@@ -731,7 +741,9 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
 #endif
                        && !conf->collect_struct
                        && !conf->collect_totals
+#ifdef HAVE_VARNISH_V3
                        && !conf->collect_uptime
+#endif
                        && !conf->collect_vcl
                        && !conf->collect_workers)
        {