From bbc501fbfd1f8ffe67b97cc684ca5c1152ccbfd1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 26 Mar 2012 21:30:43 +0400 Subject: [PATCH] * Improve statistics for scanned messages. --- src/controller.c | 22 ++++++++++++++++------ src/main.h | 7 +++---- src/protocol.c | 16 ++++------------ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/controller.c b/src/controller.c index ddac27930..6016a271d 100644 --- a/src/controller.c +++ b/src/controller.c @@ -387,8 +387,8 @@ static gboolean process_stat_command (struct controller_session *session) { gchar out_buf[BUFSIZ]; - gint r; - guint64 used, total, rev; + gint r, i; + guint64 used, total, rev, ham = 0, spam = 0; time_t ti; memory_pool_stat_t mem_st; struct classifier_config *ccf; @@ -399,10 +399,20 @@ process_stat_command (struct controller_session *session) memory_pool_stat (&mem_st); r = rspamd_snprintf (out_buf, sizeof (out_buf), "Messages scanned: %ud" CRLF, session->worker->srv->stat->messages_scanned); if (session->worker->srv->stat->messages_scanned > 0) { - r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as spam: %ud, %.2f%%" CRLF, session->worker->srv->stat->messages_spam, - (double)session->worker->srv->stat->messages_spam / (double)session->worker->srv->stat->messages_scanned * 100.); - r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as ham: %ud, %.2f%%" CRLF, session->worker->srv->stat->messages_ham, - (double)session->worker->srv->stat->messages_ham / (double)session->worker->srv->stat->messages_scanned * 100.); + for (i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i ++) { + r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages with action %s: %ud" CRLF, + str_action_metric (i), session->worker->srv->stat->actions_stat[i]); + if (i < METRIC_ACTION_GREYLIST) { + spam += session->worker->srv->stat->actions_stat[i]; + } + else { + ham += session->worker->srv->stat->actions_stat[i]; + } + } + r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as spam: %ud, %.2f%%" CRLF, spam, + (double)spam / (double)session->worker->srv->stat->messages_scanned * 100.); + r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages treated as ham: %ud, %.2f%%" CRLF, ham, + (double)ham / (double)session->worker->srv->stat->messages_scanned * 100.); } r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Messages learned: %ud" CRLF, session->worker->srv->stat->messages_learned); r += rspamd_snprintf (out_buf + r, sizeof (out_buf) - r, "Connections count: %ud" CRLF, session->worker->srv->stat->connections_count); diff --git a/src/main.h b/src/main.h index 63a94b462..2331dbdb5 100644 --- a/src/main.h +++ b/src/main.h @@ -76,10 +76,9 @@ struct worker_task; */ struct rspamd_stat { guint messages_scanned; /**< total number of messages scanned */ - guint messages_spam; /**< messages treated as spam */ - guint messages_ham; /**< messages treated as ham */ - guint connections_count; /**< total connections count */ - guint control_connections_count; /**< connections count to control interface */ + guint actions_stat[METRIC_ACTION_NOACTION + 1]; /**< statistic for each action */ + guint connections_count; /**< total connections count */ + guint control_connections_count; /**< connections count to control interface */ guint messages_learned; /**< messages learned */ guint fuzzy_hashes; /**< number of fuzzy hashes stored */ guint fuzzy_hashes_expired; /**< number of fuzzy hashes expired */ diff --git a/src/protocol.c b/src/protocol.c index 51290cdf1..b4dcd7d13 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -1170,6 +1170,10 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data metric_res->metric); } + if (G_LIKELY (action <= METRIC_ACTION_NOACTION)) { + task->worker->srv->stat->actions_stat[action] ++; + } + if (!task->is_json) { r = print_metric_data_rspamc (task, outbuf, sizeof (outbuf), metric_res, metric_res->metric, ms, rs, action); } @@ -1428,12 +1432,6 @@ write_check_reply (struct worker_task *task) /* Increase counters */ task->worker->srv->stat->messages_scanned++; - if (default_score >= default_required_score) { - task->worker->srv->stat->messages_spam ++; - } - else { - task->worker->srv->stat->messages_ham ++; - } return TRUE; } @@ -1541,12 +1539,6 @@ write_process_reply (struct worker_task *task) } task->worker->srv->stat->messages_scanned++; - if (default_score >= default_required_score) { - task->worker->srv->stat->messages_spam ++; - } - else { - task->worker->srv->stat->messages_ham ++; - } return TRUE; } -- 2.39.5