commit aabe0bf: [Feature] Output average scan time in /stat endpoint

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Feb 26 13:35:08 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-02-26 13:24:03 +0000
URL: https://github.com/rspamd/rspamd/commit/aabe0bf56510e5de3eb10e1cddc280e53a85acc8

[Feature] Output average scan time in /stat endpoint

---
 src/controller.c         | 6 ++++++
 src/libserver/protocol.c | 2 +-
 src/rspamd.c             | 5 +++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/controller.c b/src/controller.c
index 3b4fa3f46..926b8bb06 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -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 (
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 80e73b3ca..9d83ae1db 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -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;
diff --git a/src/rspamd.c b/src/rspamd.c
index 61acd9abc..8f33ccc48 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -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);


More information about the Commits mailing list