aboutsummaryrefslogtreecommitdiffstats
path: root/src/controller.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-10-14 12:44:23 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-10-14 12:44:23 +0100
commit41f51d1a129340fa8be5539f37ad5462fc6157eb (patch)
tree204b9316fa2f3d57fa3282587bfb27243efb912d /src/controller.c
parent59705b6431613ec2696c21794fb4377f4fb07fd0 (diff)
downloadrspamd-41f51d1a129340fa8be5539f37ad5462fc6157eb.tar.gz
rspamd-41f51d1a129340fa8be5539f37ad5462fc6157eb.zip
[Feature] Periodically save rspamd stats to disk
Issue: #1823
Diffstat (limited to 'src/controller.c')
-rw-r--r--src/controller.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/controller.c b/src/controller.c
index c3af1e4ba..9d39627dc 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -178,6 +178,7 @@ struct rspamd_controller_worker_ctx {
struct event *rrd_event;
struct rspamd_rrd_file *rrd;
+ struct event save_stats_event;
};
struct rspamd_controller_plugin_cbdata {
@@ -3207,6 +3208,14 @@ rspamd_controller_store_saved_stats (struct rspamd_controller_worker_ctx *ctx)
}
static void
+rspamd_controller_stats_save_periodic (int fd, short what, gpointer ud)
+{
+ struct rspamd_controller_worker_ctx *ctx = ud;
+
+ rspamd_controller_store_saved_stats (ctx);
+}
+
+static void
rspamd_controller_password_sane (struct rspamd_controller_worker_ctx *ctx,
const gchar *password, const gchar *type)
{
@@ -3603,6 +3612,8 @@ start_controller_worker (struct rspamd_worker *worker)
GHashTableIter iter;
gpointer key, value;
struct rspamd_keypair_cache *cache;
+ struct timeval stv;
+ const guint save_stats_interval = 60 * 1000; /* 1 minute */
gpointer m;
ctx->ev_base = rspamd_prepare_worker (worker,
@@ -3805,6 +3816,13 @@ start_controller_worker (struct rspamd_worker *worker)
rspamd_lua_run_postloads (ctx->cfg->lua_state, ctx->cfg, ctx->ev_base, worker);
+ /* Schedule periodic stats saving, see #1823 */
+ evtimer_set (&ctx->save_stats_event, rspamd_controller_stats_save_periodic,
+ ctx);
+ event_base_set (ctx->ev_base, &ctx->save_stats_event);
+ msec_to_tv (save_stats_interval, &stv);
+ evtimer_add (&ctx->save_stats_event, &stv);
+
/* Start event loop */
event_base_loop (ctx->ev_base, 0);
rspamd_worker_block_signals ();