From a95c95f74c345c0a6fd00f536cde0d46ee614335 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 3 Nov 2014 12:27:09 +0100 Subject: [PATCH] stats: introduce global config 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 | 30 ++++++++++++++++++++++++++++++ suricata.yaml.in | 10 +++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/counters.c b/src/counters.c index 5ea17c55e2..ec28d2e062 100644 --- a/src/counters.c +++ b/src/counters.c @@ -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); diff --git a/suricata.yaml.in b/suricata.yaml.in index 70be178bad..4e8efd08b9 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -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: