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.
pull/1234/head
Victor Julien 11 years ago
parent e98346b555
commit a95c95f74c

@ -146,6 +146,23 @@ void SCPerfCounterSetUI64(uint16_t id, SCPerfCounterArray *pca,
return; 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 * \brief Initializes the output interface context
* *
@ -160,6 +177,19 @@ static void SCPerfInitOPCtx(void)
} }
memset(sc_perf_op_ctx, 0, sizeof(SCPerfOPIfaceContext)); 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 */ /* Store the engine start time */
time(&sc_start_time); time(&sc_start_time);

@ -72,6 +72,13 @@ unix-command:
enabled: no enabled: no
#filename: custom.socket #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. # Configure the type of alert (and other) logging you would like.
outputs: outputs:
@ -235,12 +242,9 @@ outputs:
log-packet-header: yes log-packet-header: yes
# Stats.log contains data from various counters of the suricata engine. # 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: - stats:
enabled: yes enabled: yes
filename: stats.log filename: stats.log
interval: 8
# a line based alerts log similar to fast.log into syslog # a line based alerts log similar to fast.log into syslog
- syslog: - syslog:

Loading…
Cancel
Save