]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add ability to log mempool usage for a task
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 12 Dec 2019 20:27:03 +0000 (20:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 12 Dec 2019 20:27:03 +0000 (20:27 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_utils.c
src/libserver/task.c

index fbddd90963a8c86be05b1083407e0769a1c40024..8e1ce2c42c84e427d741678eea251ab1bdc86862 100644 (file)
@@ -262,6 +262,8 @@ enum rspamd_log_format_type {
        RSPAMD_LOG_SETTINGS_ID,
        RSPAMD_LOG_GROUPS,
        RSPAMD_LOG_PUBLIC_GROUPS,
+       RSPAMD_LOG_MEMPOOL_SIZE,
+       RSPAMD_LOG_MEMPOOL_WASTE,
 };
 
 enum rspamd_log_format_flags {
index 857f7a0ac5c9c8ee9884221bf2433832ce31ba2f..76731eec453c7457bef6cbbf8082af3ebfc2e2d8 100644 (file)
@@ -518,6 +518,12 @@ rspamd_config_process_var (struct rspamd_config *cfg, const rspamd_ftok_t *var,
        else if (rspamd_ftok_cstr_equal (&tok, "settings_id", TRUE)) {
                type = RSPAMD_LOG_SETTINGS_ID;
        }
+       else if (rspamd_ftok_cstr_equal (&tok, "mempool_size", TRUE)) {
+               type = RSPAMD_LOG_MEMPOOL_SIZE;
+       }
+       else if (rspamd_ftok_cstr_equal (&tok, "mempool_waste", TRUE)) {
+               type = RSPAMD_LOG_MEMPOOL_WASTE;
+       }
        else {
                msg_err_config ("unknown log variable: %T", &tok);
                return FALSE;
index 2fb9bf1d9797803d84a0f718ec5b4e7265a228b2..7cdce32f3da34ed7751679dc70f192cb4f98b2c9 100644 (file)
@@ -1544,6 +1544,18 @@ rspamd_task_log_variable (struct rspamd_task *task,
                        var.len = sizeof (undef) - 1;
                }
                break;
+       case RSPAMD_LOG_MEMPOOL_SIZE:
+               var.len = rspamd_snprintf (numbuf, sizeof (numbuf),
+                               "%Hz",
+                               task->task_pool->used_memory);
+               var.begin = numbuf;
+               break;
+       case RSPAMD_LOG_MEMPOOL_WASTE:
+               var.len = rspamd_snprintf (numbuf, sizeof (numbuf),
+                               "%Hz",
+                               task->task_pool->wasted_memory);
+               var.begin = numbuf;
+               break;
        default:
                var = rspamd_task_log_metric_res (task, lf);
                break;