aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-09-16 17:01:18 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-09-16 17:01:18 +0100
commitd4be8b2d633c57f8f3695dbe4ce9e3407bc1046b (patch)
tree1b3576d33e3b86491c9cb059f69c62819a4db108
parent339578344c74f5bb971f4a717dbd1e38e6c30ad8 (diff)
downloadrspamd-d4be8b2d633c57f8f3695dbe4ce9e3407bc1046b.tar.gz
rspamd-d4be8b2d633c57f8f3695dbe4ce9e3407bc1046b.zip
[Feature] Output number of messages processed to proctitle
-rw-r--r--src/rspamd.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/rspamd.c b/src/rspamd.c
index 808ca6aaa..d0dd7ff10 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -83,6 +83,8 @@ static void rspamd_cld_handler (EV_P_ ev_child *w,
/* Control socket */
static gint control_fd;
static ev_io control_ev;
+static struct rspamd_stat old_stat;
+static ev_timer stat_ev;
static gboolean valgrind_mode = FALSE;
@@ -969,6 +971,39 @@ rspamd_usr1_handler (struct ev_loop *loop, ev_signal *w, int revents)
}
static void
+rspamd_stat_update_handler (struct ev_loop *loop, ev_timer *w, int revents)
+{
+ struct rspamd_main *rspamd_main = (struct rspamd_main *)w->data;
+ struct rspamd_stat cur_stat;
+ gchar proctitle[128];
+
+ memcpy (&cur_stat, rspamd_main->stat, sizeof (cur_stat));
+
+ if (old_stat.messages_scanned > 0 &&
+ cur_stat.messages_scanned > old_stat.messages_scanned) {
+ gdouble rate = (double)(cur_stat.messages_scanned - old_stat.messages_scanned) /
+ w->repeat;
+ gdouble old_spam = old_stat.actions_stat[METRIC_ACTION_REJECT] +
+ old_stat.actions_stat[METRIC_ACTION_ADD_HEADER] +
+ old_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT];
+ gdouble old_ham = old_stat.actions_stat[METRIC_ACTION_NOACTION];
+ gdouble new_spam = cur_stat.actions_stat[METRIC_ACTION_REJECT] +
+ cur_stat.actions_stat[METRIC_ACTION_ADD_HEADER] +
+ cur_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT];
+ gdouble new_ham = cur_stat.actions_stat[METRIC_ACTION_NOACTION];
+
+ rspamd_snprintf (proctitle, sizeof (proctitle),
+ "main process; %.1f msg/sec, %.1f msg/sec spam, %.1f msg/sec ham",
+ rate,
+ (new_spam - old_spam) / w->repeat,
+ (new_ham - old_ham) / w->repeat);
+ setproctitle (proctitle);
+ }
+
+ memcpy (&old_stat, &cur_stat, sizeof (cur_stat));
+}
+
+static void
rspamd_hup_handler (struct ev_loop *loop, ev_signal *w, int revents)
{
struct rspamd_main *rspamd_main = (struct rspamd_main *)w->data;
@@ -1375,6 +1410,15 @@ main (gint argc, gchar **argv, gchar **env)
rspamd_main->usr1_ev.data = rspamd_main;
ev_signal_start (event_loop, &rspamd_main->usr1_ev);
+ /* Update proctitle according to number of messages processed */
+ static const ev_tstamp stat_update_time = 10.0;
+
+ memset (&old_stat, 0, sizeof (old_stat));
+ stat_ev.data = rspamd_main;
+ ev_timer_init (&stat_ev, rspamd_stat_update_handler,
+ stat_update_time, stat_update_time);
+ ev_timer_start (event_loop, &stat_ev);
+
rspamd_check_core_limits (rspamd_main);
rspamd_mempool_lock_mutex (rspamd_main->start_mtx);
spawn_workers (rspamd_main, event_loop);