aboutsummaryrefslogtreecommitdiffstats
path: root/src/controller.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller.c')
-rw-r--r--src/controller.c85
1 files changed, 14 insertions, 71 deletions
diff --git a/src/controller.c b/src/controller.c
index 5526d9197..8ba12b605 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -3094,22 +3094,21 @@ rspamd_controller_handle_metrics_common(
gboolean do_reset)
{
struct rspamd_controller_session *session = conn_ent->ud;
- ucl_object_t *top, *sub;
- int i;
- int64_t uptime;
- uint64_t spam = 0, ham = 0;
- rspamd_mempool_stat_t mem_st;
- struct rspamd_stat *stat, stat_copy;
+ ucl_object_t *top;
+ ev_tstamp uptime;
+ struct rspamd_stat stat_copy;
struct rspamd_controller_worker_ctx *ctx;
struct rspamd_task *task;
struct rspamd_stat_cbdata *cbdata;
- memset(&mem_st, 0, sizeof(mem_st));
- rspamd_mempool_stat(&mem_st);
- memcpy(&stat_copy, session->ctx->worker->srv->stat, sizeof(stat_copy));
- stat = &stat_copy;
+ uptime = ev_time() - session->ctx->start_time;
ctx = session->ctx;
+ memcpy(&stat_copy, session->ctx->worker->srv->stat, sizeof(stat_copy));
+ top = rspamd_worker_metrics_object(session->ctx->cfg, &stat_copy, uptime);
+ ucl_object_insert_key(top, ucl_object_fromint(session->ctx->start_time), "start_time", 0, false);
+ ucl_object_insert_key(top, ucl_object_frombool(session->is_read_only),
+ "read_only", 0, false);
task = rspamd_task_new(session->ctx->worker, session->cfg, session->pool,
ctx->lang_det, ctx->event_loop, FALSE);
task->resolver = ctx->resolver;
@@ -3117,7 +3116,6 @@ rspamd_controller_handle_metrics_common(
cbdata->conn_ent = conn_ent;
cbdata->task = task;
cbdata->ctx = ctx;
- top = ucl_object_typed_new(UCL_OBJECT);
cbdata->top = top;
task->s = rspamd_session_create(session->pool,
@@ -3127,75 +3125,20 @@ rspamd_controller_handle_metrics_common(
cbdata);
task->fin_arg = cbdata;
task->http_conn = rspamd_http_connection_ref(conn_ent->conn);
- ;
task->sock = conn_ent->conn->fd;
- ucl_object_insert_key(top, ucl_object_fromstring(RVERSION), "version", 0, false);
- ucl_object_insert_key(top, ucl_object_fromstring(session->ctx->cfg->checksum), "config_id", 0, false);
- uptime = ev_time() - session->ctx->start_time;
- ucl_object_insert_key(top, ucl_object_fromint(uptime), "uptime", 0, false);
- ucl_object_insert_key(top, ucl_object_fromint(session->ctx->start_time), "start_time", 0, false);
- ucl_object_insert_key(top, ucl_object_frombool(session->is_read_only),
- "read_only", 0, false);
- ucl_object_insert_key(top, ucl_object_fromint(stat->messages_scanned), "scanned", 0, false);
- ucl_object_insert_key(top, ucl_object_fromint(stat->messages_learned), "learned", 0, false);
+ if (stat_copy.messages_scanned > 0 && do_reset) {
+ for (int i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i++) {
- if (stat->messages_scanned > 0) {
- sub = ucl_object_typed_new(UCL_OBJECT);
- for (i = METRIC_ACTION_REJECT; i <= METRIC_ACTION_NOACTION; i++) {
- ucl_object_insert_key(sub,
- ucl_object_fromint(stat->actions_stat[i]),
- rspamd_action_to_str(i), 0, false);
- if (i < METRIC_ACTION_GREYLIST) {
- spam += stat->actions_stat[i];
- }
- else {
- ham += stat->actions_stat[i];
- }
- if (do_reset) {
#ifndef HAVE_ATOMIC_BUILTINS
- session->ctx->worker->srv->stat->actions_stat[i] = 0;
+ session->ctx->worker->srv->stat->actions_stat[i] = 0;
#else
- __atomic_store_n(&session->ctx->worker->srv->stat->actions_stat[i],
- 0, __ATOMIC_RELEASE);
+ __atomic_store_n(&session->ctx->worker->srv->stat->actions_stat[i],
+ 0, __ATOMIC_RELEASE);
#endif
- }
}
- ucl_object_insert_key(top, sub, "actions", 0, false);
}
- ucl_object_insert_key(top, ucl_object_fromint(spam), "spam_count", 0, false);
- ucl_object_insert_key(top, ucl_object_fromint(ham), "ham_count", 0, false);
- ucl_object_insert_key(top,
- ucl_object_fromint(stat->connections_count), "connections", 0, false);
- ucl_object_insert_key(top,
- 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);
- ucl_object_insert_key(top,
- ucl_object_fromint(mem_st.pools_freed), "pools_freed", 0, false);
- ucl_object_insert_key(top,
- ucl_object_fromint(mem_st.bytes_allocated), "bytes_allocated", 0,
- false);
- ucl_object_insert_key(top,
- ucl_object_fromint(
- mem_st.chunks_allocated),
- "chunks_allocated", 0, false);
- ucl_object_insert_key(top,
- ucl_object_fromint(mem_st.shared_chunks_allocated),
- "shared_chunks_allocated", 0, false);
- ucl_object_insert_key(top,
- ucl_object_fromint(mem_st.chunks_freed), "chunks_freed", 0, false);
- ucl_object_insert_key(top,
- ucl_object_fromint(
- mem_st.oversized_chunks),
- "chunks_oversized", 0, false);
- ucl_object_insert_key(top,
- ucl_object_fromint(mem_st.fragmented_size), "fragmented", 0, false);
-
if (do_reset) {
session->ctx->srv->stat->messages_scanned = 0;
session->ctx->srv->stat->messages_learned = 0;