unix-socket: restore dump-counters functionality

Create a eve.stats like output for dump-counters.
pull/1867/head
Victor Julien 10 years ago
parent 310e8fcbf8
commit 14030239f8

@ -36,7 +36,10 @@
#include "util-privs.h" #include "util-privs.h"
#include "util-signal.h" #include "util-signal.h"
#include "unix-manager.h" #include "unix-manager.h"
#include "output.h" #include "output.h"
#include "output-stats.h"
#include "output-json-stats.h"
/* Time interval for syncing the local counters with the global ones */ /* Time interval for syncing the local counters with the global ones */
#define STATS_WUT_TTS 3 #define STATS_WUT_TTS 3
@ -101,6 +104,7 @@ void StatsReleaseCounters(StatsCounter *head);
/** stats table is filled each interval and passed to the /** stats table is filled each interval and passed to the
* loggers. Initialized at first use. */ * loggers. Initialized at first use. */
static StatsTable stats_table = { NULL, NULL, 0, 0, 0, {0 , 0}}; static StatsTable stats_table = { NULL, NULL, 0, 0, 0, {0 , 0}};
static SCMutex stats_table_mutex = SCMUTEX_INITIALIZER;
static uint16_t counters_global_id = 0; static uint16_t counters_global_id = 0;
@ -280,6 +284,7 @@ static void StatsReleaseCtx()
SCFree(stats_ctx); SCFree(stats_ctx);
stats_ctx = NULL; stats_ctx = NULL;
SCMutexLock(&stats_table_mutex);
/* free stats table */ /* free stats table */
if (stats_table.tstats != NULL) { if (stats_table.tstats != NULL) {
SCFree(stats_table.tstats); SCFree(stats_table.tstats);
@ -291,6 +296,7 @@ static void StatsReleaseCtx()
stats_table.stats = NULL; stats_table.stats = NULL;
} }
memset(&stats_table, 0, sizeof(stats_table)); memset(&stats_table, 0, sizeof(stats_table));
SCMutexUnlock(&stats_table_mutex);
return; return;
} }
@ -359,7 +365,9 @@ static void *StatsMgmtThread(void *arg)
SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time); SCCtrlCondTimedwait(tv_local->ctrl_cond, tv_local->ctrl_mutex, &cond_time);
SCCtrlMutexUnlock(tv_local->ctrl_mutex); SCCtrlMutexUnlock(tv_local->ctrl_mutex);
SCMutexLock(&stats_table_mutex);
StatsOutput(tv_local); StatsOutput(tv_local);
SCMutexUnlock(&stats_table_mutex);
if (TmThreadsCheckFlag(tv_local, THV_KILL)) { if (TmThreadsCheckFlag(tv_local, THV_KILL)) {
run = 0; run = 0;
@ -757,15 +765,25 @@ static int StatsOutput(ThreadVars *tv)
} }
#ifdef BUILD_UNIX_SOCKET #ifdef BUILD_UNIX_SOCKET
/** /** \brief callback for getting stats into unix socket
* \todo reimplement this, probably based on stats-json
*/ */
TmEcode StatsOutputCounterSocket(json_t *cmd, TmEcode StatsOutputCounterSocket(json_t *cmd,
json_t *answer, void *data) json_t *answer, void *data)
{ {
json_object_set_new(answer, "message", json_t *message = NULL;
json_string("not implemented")); TmEcode r = TM_ECODE_OK;
return TM_ECODE_FAILED;
SCMutexLock(&stats_table_mutex);
if (stats_table.start_time == 0) {
r = TM_ECODE_FAILED;
message = json_string("stats not yet synchronized");
} else {
message = StatsToJSON(&stats_table, JSON_STATS_TOTALS|JSON_STATS_THREADS);
}
SCMutexUnlock(&stats_table_mutex);
json_object_set_new(answer, "message", message);
return r;
} }
#endif /* BUILD_UNIX_SOCKET */ #endif /* BUILD_UNIX_SOCKET */

@ -45,6 +45,7 @@
#include "util-crypt.h" #include "util-crypt.h"
#include "output-json.h" #include "output-json.h"
#include "output-json-stats.h"
#define MODULE_NAME "JsonStatsLog" #define MODULE_NAME "JsonStatsLog"

Loading…
Cancel
Save