]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add average scan time metric
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 5 Mar 2022 21:02:09 +0000 (21:02 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 5 Mar 2022 21:02:09 +0000 (21:02 +0000)
Issue: #4096

src/controller.c

index 7531080c218cb505806522443ec31ad5d57c45a9..57586f3a92dd3e84e33d44fabf38cbd2fcb2772e 100644 (file)
@@ -2563,6 +2563,7 @@ rspamd_controller_handle_savemap (struct rspamd_http_connection_entry *conn_ent,
 
 struct rspamd_stat_cbdata {
        struct rspamd_http_connection_entry *conn_ent;
+       struct rspamd_controller_worker_ctx *ctx;
        ucl_object_t *top;
        ucl_object_t *stat;
        struct rspamd_task *task;
@@ -2655,6 +2656,7 @@ rspamd_controller_handle_stat_common (
        cbdata = rspamd_mempool_alloc0 (session->pool, sizeof (*cbdata));
        cbdata->conn_ent = conn_ent;
        cbdata->task = task;
+       cbdata->ctx = ctx;
        top = ucl_object_typed_new (UCL_OBJECT);
        cbdata->top = top;
 
@@ -2719,6 +2721,7 @@ rspamd_controller_handle_stat_common (
                ucl_object_fromint (stat->control_connections_count),
                "control_connections", 0, false);
 
+
        ucl_object_insert_key (top,
                ucl_object_fromint (mem_st.pools_allocated), "pools_allocated", 0,
                false);
@@ -2834,6 +2837,13 @@ rspamd_controller_metrics_fin_task (void *ud) {
        rspamd_printf_fstring (&output, "rspamd_config{id=\"%s\"} 1\n",
                ucl_object_tostring (ucl_object_lookup (top, "config_id")));
 
+       gsize cnt = MAX_AVG_TIME_SLOTS;
+       float sum = rspamd_sum_floats (cbdata->ctx->worker->srv->stat->avg_time.avg_time, &cnt);
+       rspamd_printf_fstring (&output, "# HELP rspamd_scan_time_average Average messages scan time.\n");
+       rspamd_printf_fstring (&output, "# TYPE rspamd_scan_time_average gauge\n");
+       rspamd_printf_fstring (&output, "rspamd_scan_time_average %f\n",
+                       cnt > 0 ? (double)sum / cnt : 0.0);
+
        rspamd_controller_metrics_add_integer(&output, top,
                        "process_start_time_seconds",
                        "gauge",
@@ -3085,6 +3095,7 @@ rspamd_controller_handle_metrics_common (
        cbdata = rspamd_mempool_alloc0 (session->pool, sizeof (*cbdata));
        cbdata->conn_ent = conn_ent;
        cbdata->task = task;
+       cbdata->ctx = ctx;
        top = ucl_object_typed_new (UCL_OBJECT);
        cbdata->top = top;