aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/rspamd_control.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-21 11:56:17 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-21 11:56:17 +0100
commit196499cda2dcf4d4ae1faaecf9cd68fda55fac81 (patch)
treeec853169985d5933ca5096e693ef235ddd905e89 /src/libserver/rspamd_control.c
parent91132dd0c187bd422c159ad3f0656e476f99a9b2 (diff)
downloadrspamd-196499cda2dcf4d4ae1faaecf9cd68fda55fac81.tar.gz
rspamd-196499cda2dcf4d4ae1faaecf9cd68fda55fac81.zip
[Minor] Add health check command for control interface
Diffstat (limited to 'src/libserver/rspamd_control.c')
-rw-r--r--src/libserver/rspamd_control.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index f1de1d29c..0021485c3 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -850,6 +850,31 @@ rspamd_control_handle_on_fork (struct rspamd_srv_command *cmd,
}
}
+static void
+rspamd_fill_health_reply (struct rspamd_main *srv, struct rspamd_srv_reply *rep)
+{
+ GHashTableIter it;
+ gpointer k, v;
+
+ memset (&rep->reply.health, 0, sizeof (rep->reply));
+ g_hash_table_iter_init (&it, srv->workers);
+
+ while (g_hash_table_iter_next (&it, &k, &v)) {
+ struct rspamd_worker *wrk = (struct rspamd_worker *)v;
+
+ if (wrk->hb.nbeats < 0) {
+ rep->reply.health.workers_hb_lost ++;
+ }
+ else if (rspamd_worker_is_scanner (wrk)) {
+ rep->reply.health.scanners_count ++;
+ }
+
+ rep->reply.health.workers_count ++;
+ }
+
+ rep->reply.status = (g_hash_table_size (srv->workers) > 0);
+}
+
static void
rspamd_srv_handler (EV_P_ ev_io *w, int revents)
@@ -979,6 +1004,9 @@ rspamd_srv_handler (EV_P_ ev_io *w, int revents)
worker->hb.last_event = ev_time ();
rdata->rep.reply.heartbeat.status = 0;
break;
+ case RSPAMD_SRV_HEALTH:
+ rspamd_fill_health_reply (srv, &rdata->rep);
+ break;
default:
msg_err ("unknown command type: %d", cmd.type);
break;