]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Output average scan time in /stat endpoint
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Feb 2022 13:24:03 +0000 (13:24 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Feb 2022 13:32:26 +0000 (13:32 +0000)
src/controller.c
src/libserver/protocol.c
src/rspamd.c

index 3b4fa3f469f8feef09509e4a67642f938e331a61..926b8bb06a881219ccf7cef539074394df93c81c 100644 (file)
@@ -2703,6 +2703,12 @@ rspamd_controller_handle_stat_common (
        }
        ucl_object_insert_key (top, sub, "actions", 0, false);
 
+       sub = ucl_object_typed_new (UCL_ARRAY);
+       for (i = 0; i < MAX_AVG_TIME_SLOTS; i++) {
+               ucl_array_append (sub, ucl_object_fromdouble (stat->avg_time.avg_time[i]));
+       }
+       ucl_object_insert_key (top, sub, "scan_times", 0, false);
+
        ucl_object_insert_key (top, ucl_object_fromint (
                        spam), "spam_count", 0, false);
        ucl_object_insert_key (top, ucl_object_fromint (
index 80e73b3cab0fa535d678445442a8d4336907a5bc..9d83ae1db7cdeded3aa4d739b46d30130cd00a00 100644 (file)
@@ -1822,7 +1822,7 @@ end:
 #ifndef HAVE_ATOMIC_BUILTINS
                slot = task->worker->srv->stat->avg_time.cur_slot++;
 #else
-               slot = __atomic_add_fetch (&task->worker->srv->stat->avg_time.cur_slot,
+               slot = __atomic_fetch_add (&task->worker->srv->stat->avg_time.cur_slot,
                                1, __ATOMIC_RELEASE);
 #endif
                slot = slot % MAX_AVG_TIME_SLOTS;
index 61acd9abc33760c65b89293db428294fb4b79613..8f33ccc48521a2bed8dcb0cdd016197cff50b7ad 100644 (file)
@@ -1370,6 +1370,11 @@ main (gint argc, gchar **argv, gchar **env)
                        sizeof (struct rspamd_stat),
                                        RSPAMD_ALIGNOF(struct rspamd_stat),
                        G_STRLOC);
+       /* Set all time slots to nan */
+       for (i = 0; i < MAX_AVG_TIME_SLOTS; i ++) {
+               rspamd_main->stat->avg_time.avg_time[i] = NAN;
+       }
+
        rspamd_main->cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
        rspamd_main->spairs = g_hash_table_new_full (rspamd_spair_hash,
                        rspamd_spair_equal, g_free, rspamd_spair_close);