]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Allow logging of re_cache statistics
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 14:43:08 +0000 (14:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 14:43:08 +0000 (14:43 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/protocol.c

index 36e6371d8de90647c436ea27a9f67d267c3ba91d..511b18b2570c6053c4cfbdaa7eade4eeb48c4514 100644 (file)
@@ -247,6 +247,7 @@ struct rspamd_config {
        gboolean log_color;                             /**< output colors for console output                   */
        gboolean log_extended;                          /**< log extended information                                                   */
        gboolean log_systemd;                           /**< special case for systemd logger                                    */
+       gboolean log_re_cache;                          /**< show statistics about regexps                                              */
 
        gboolean mlock_statfile_pool;                   /**< use mlock (2) for locking statfiles                                */
 
index bbe241cb120d35884d77fb753169d552af9eb146..1999dd3519effbf6522190b2c7eeabec412ff57b 100644 (file)
@@ -1257,6 +1257,11 @@ rspamd_rcl_config_init (void)
                        rspamd_rcl_parse_struct_boolean,
                        G_STRUCT_OFFSET (struct rspamd_config, log_urls),
                        0);
+       rspamd_rcl_add_default_handler (sub,
+                       "log_re_cache",
+                       rspamd_rcl_parse_struct_boolean,
+                       G_STRUCT_OFFSET (struct rspamd_config, log_re_cache),
+                       0);
        rspamd_rcl_add_default_handler (sub,
                        "debug_ip",
                        rspamd_rcl_parse_struct_string,
index d6acd6e74a55dea568e8f5da117ed3ae582d509e..b140ca2c6cbc7dbbb608102eadc122a74cb6f7e2 100644 (file)
@@ -991,6 +991,7 @@ rspamd_protocol_http_reply (struct rspamd_http_message *msg,
 {
        struct metric_result *metric_res;
        GHashTableIter hiter;
+       const struct rspamd_re_cache_stat *restat;
        gpointer h, v;
        ucl_object_t *top = NULL;
        gdouble required_score;
@@ -1012,6 +1013,18 @@ rspamd_protocol_http_reply (struct rspamd_http_message *msg,
 
        rspamd_task_write_log (task);
 
+       if (task->cfg->log_re_cache) {
+               restat = rspamd_re_cache_get_stat (task->re_rt);
+               g_assert (restat != NULL);
+               msg_info_task (
+                               "regexp statistics: %ud pcre regexps scanned, %ud regexps matched,"
+                                               " %HL bytes scanned using pcre, %HL bytes scanned total",
+                               restat->regexp_checked,
+                               restat->regexp_matched,
+                               restat->bytes_scanned_pcre,
+                               restat->bytes_scanned);
+       }
+
        msg->body = rspamd_fstring_sized_new (1000);
 
        if (msg->method < HTTP_SYMBOLS && !RSPAMD_TASK_IS_SPAMC (task)) {