]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stats log: suppress 0 counters by default
authorVictor Julien <victor@inliniac.net>
Sun, 8 Nov 2015 08:55:00 +0000 (09:55 +0100)
committerVictor Julien <victor@inliniac.net>
Sun, 6 Dec 2015 09:49:29 +0000 (10:49 +0100)
src/log-stats.c
suricata.yaml.in

index 5fcb1c9f62df0a4766c98af36dca42aa13561485..385dec2bb4fcc70c4e5445375cb452c421f5ddd4 100644 (file)
@@ -51,6 +51,7 @@
 
 #define LOG_STATS_TOTALS  (1<<0)
 #define LOG_STATS_THREADS (1<<1)
+#define LOG_STATS_NULLS   (1<<2)
 
 TmEcode LogStatsLogThreadInit(ThreadVars *, void *, void **);
 TmEcode LogStatsLogThreadDeinit(ThreadVars *, void *);
@@ -108,6 +109,9 @@ int LogStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *st)
             if (st->stats[u].name == NULL)
                 continue;
 
+            if (!(aft->statslog_ctx->flags & LOG_STATS_NULLS) && st->stats[u].value == 0)
+                continue;
+
             char line[1024];
             size_t len = snprintf(line, sizeof(line), "%-25s | %-25s | %-" PRIu64 "\n",
                     st->stats[u].name, st->stats[u].tm_name, st->stats[u].value);
@@ -238,6 +242,7 @@ OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
     if (conf != NULL) {
         const char *totals = ConfNodeLookupChildValue(conf, "totals");
         const char *threads = ConfNodeLookupChildValue(conf, "threads");
+        const char *nulls = ConfNodeLookupChildValue(conf, "null-values");
         SCLogDebug("totals %s threads %s", totals, threads);
 
         if (totals != NULL && ConfValIsFalse(totals)) {
@@ -246,6 +251,9 @@ OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
         if (threads != NULL && ConfValIsTrue(threads)) {
             statslog_ctx->flags |= LOG_STATS_THREADS;
         }
+        if (nulls != NULL && ConfValIsTrue(nulls)) {
+            statslog_ctx->flags |= LOG_STATS_NULLS;
+        }
         SCLogDebug("statslog_ctx->flags %08x", statslog_ctx->flags);
     }
 
index a612fb25dedd813ecf3c73beb892ddd04ee338e7..67abc18a6a3fda4491cc4653c88e2af09abcc1ca 100644 (file)
@@ -315,6 +315,7 @@ outputs:
       filename: stats.log
       totals: yes       # stats for all threads merged together
       threads: no       # per thread stats
+      #null-values: yes  # print counters that have value 0
 
   # a line based alerts log similar to fast.log into syslog
   - syslog: