]> source.dussan.org Git - rspamd.git/commitdiff
* Improve statistics for scanned messages.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 26 Mar 2012 17:30:43 +0000 (21:30 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 26 Mar 2012 17:30:43 +0000 (21:30 +0400)
src/controller.c
src/main.h
src/protocol.c

index ddac279306b882f2ba3f1d04db0da14157b1cfa5..6016a271d15ddcaa8b3033d0840c9c5592c7d110 100644 (file)
@@ -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);
index 63a94b462294a73ee443166c1542373ea7fd4db0..2331dbdb5043b3196e59d5abc852ae4b41ed7e40 100644 (file)
@@ -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                                     */
index 51290cdf1fc734da14fcde001690b226b871e2ad..b4dcd7d13803d3eb90d650c9b672f0ab3d4304ca 100644 (file)
@@ -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;
 }