]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
json-stats: reorg threads and totals 1544/head
authorJason Ish <ish@unx.ca>
Wed, 10 Jun 2015 21:15:19 +0000 (15:15 -0600)
committerJason Ish <ish@unx.ca>
Wed, 10 Jun 2015 21:20:45 +0000 (15:20 -0600)
Totals are now placed at the top level instead of under a "Total"
object.

Threads are placed under a "threads" object.

src/output-json-stats.c

index 8db88d7c97f34025a3f2e52637418d66f4cd3a94..3e1d45e28bae5ebdff2256dd1f0c2dfadc2e9501 100644 (file)
@@ -123,19 +123,27 @@ static int JsonStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *
         for (u = 0; u < st->nstats; u++) {
             if (st->stats[u].name == NULL)
                 continue;
-            char str[256];
-            snprintf(str, sizeof(str), "%s.%s", st->stats[u].tm_name, st->stats[u].name);
-            json_t *js_type = OutputStats2Json(js_stats, str);
+            const char *name = st->stats[u].name;
+            const char *shortname = name;
+            if (rindex(name, '.') != NULL) {
+                shortname = &name[rindex(name, '.') - name + 1];
+            }
+            json_t *js_type = OutputStats2Json(js_stats, name);
             if (js_type != NULL) {
-                json_object_set_new(js_type, &str[rindex(str, '.')-str+1],
-                                    json_integer(st->stats[u].value));
+                json_object_set_new(js_type, shortname,
+                    json_integer(st->stats[u].value));
             }
         }
     }
 
-    /* per thread stats */
+    /* per thread stats - stored in a "threads" object. */
     if (st->tstats != NULL && (aft->statslog_ctx->flags & JSON_STATS_THREADS)) {
         /* for each thread (store) */
+        json_t *threads = json_object();
+        if (unlikely(threads == NULL)) {
+            json_decref(js);
+            return 0;
+        }
         uint32_t x;
         for (x = 0; x < st->ntstats; x++) {
             uint32_t offset = x * st->nstats;
@@ -147,13 +155,14 @@ static int JsonStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *
 
                 char str[256];
                 snprintf(str, sizeof(str), "%s.%s", st->tstats[u].tm_name, st->tstats[u].name);
-                json_t *js_type = OutputStats2Json(js_stats, str);
+                json_t *js_type = OutputStats2Json(threads, str);
 
                 if (js_type != NULL) {
                     json_object_set_new(js_type, &str[rindex(str, '.')-str+1], json_integer(st->tstats[u].value));
                 }
             }
         }
+        json_object_set_new(js_stats, "threads", threads);
     }
 
     json_object_set_new(js, "stats", js_stats);