]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stats: introduce global config
authorVictor Julien <victor@inliniac.net>
Mon, 3 Nov 2014 11:27:09 +0000 (12:27 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 3 Dec 2014 10:40:16 +0000 (11:40 +0100)
As the stats api calls the loggers at a global interval, the global
interval should be configured globally.

 # global stats configuration
 stats:
   enabled: yes
   # The interval field (in seconds) controls at what interval
   # the loggers are invoked.
   interval: 8

If this config isn't found, the old config will be supported.

src/counters.c
suricata.yaml.in

index 5ea17c55e2cbf508890d56f27fea91aa77e72e21..ec28d2e062db74e2ab0ee3816add1de132de7d3d 100644 (file)
@@ -146,6 +146,23 @@ void SCPerfCounterSetUI64(uint16_t id, SCPerfCounterArray *pca,
     return;
 }
 
+static ConfNode *GetConfig(void) {
+    ConfNode *stats = ConfGetNode("stats");
+    if (stats != NULL)
+        return stats;
+
+    ConfNode *root = ConfGetNode("outputs");
+    ConfNode *node = NULL;
+    if (root != NULL) {
+        TAILQ_FOREACH(node, &root->head, next) {
+            if (strcmp(node->val, "stats") == 0) {
+                return node->head.tqh_first;
+            }
+        }
+    }
+    return NULL;
+}
+
 /**
  * \brief Initializes the output interface context
  *
@@ -160,6 +177,19 @@ static void SCPerfInitOPCtx(void)
     }
     memset(sc_perf_op_ctx, 0, sizeof(SCPerfOPIfaceContext));
 
+    ConfNode *stats = GetConfig();
+    if (stats != NULL) {
+        const char *enabled = ConfNodeLookupChildValue(stats, "enabled");
+        if (enabled != NULL && ConfValIsFalse(enabled)) {
+            sc_counter_enabled = FALSE;
+            SCLogDebug("Stats module has been disabled");
+            SCReturn;
+        }
+        const char *interval = ConfNodeLookupChildValue(stats, "interval");
+        if (interval != NULL)
+            sc_counter_tts = (uint32_t) atoi(interval);
+    }
+
     /* Store the engine start time */
     time(&sc_start_time);
 
index 70be178badd6c503ede913c1a674b7352dd6e993..4e8efd08b98cc2f839d72409903ba060cb0add2d 100644 (file)
@@ -72,6 +72,13 @@ unix-command:
   enabled: no
   #filename: custom.socket
 
+# global stats configuration
+stats:
+  enabled: yes
+  # The interval field (in seconds) controls at what interval
+  # the loggers are invoked.
+  interval: 8
+
 # Configure the type of alert (and other) logging you would like.
 outputs:
 
@@ -235,12 +242,9 @@ outputs:
       log-packet-header: yes
 
   # Stats.log contains data from various counters of the suricata engine.
-  # The interval field (in seconds) tells after how long output will be written
-  # on the log file.
   - stats:
       enabled: yes
       filename: stats.log
-      interval: 8
 
   # a line based alerts log similar to fast.log into syslog
   - syslog: