]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add health check command for control interface
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 21 Jul 2021 10:56:17 +0000 (11:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 21 Jul 2021 10:56:17 +0000 (11:56 +0100)
src/libserver/rspamd_control.c
src/libserver/rspamd_control.h

index f1de1d29ca76e8bbfa2523de8a4b1692e0c2bd26..0021485c38a325ae9b05fa944271225e4110b97c 100644 (file)
@@ -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;
index 21ab1a663ae23a9a1cc2a896f09d53bbf644676c..1b57560222770ae209b3a76cd0f7a463bd19da6d 100644 (file)
@@ -48,6 +48,7 @@ enum rspamd_srv_type {
        RSPAMD_SRV_LOG_PIPE,
        RSPAMD_SRV_ON_FORK,
        RSPAMD_SRV_HEARTBEAT,
+       RSPAMD_SRV_HEALTH,
 };
 
 enum rspamd_log_pipe_type {
@@ -172,6 +173,9 @@ struct rspamd_srv_command {
                        guint status;
                        /* TODO: add more fields */
                } heartbeat;
+               struct {
+                       guint status;
+               } health;
        } cmd;
 };
 
@@ -197,6 +201,12 @@ struct rspamd_srv_reply {
                struct {
                        gint status;
                } heartbeat;
+               struct {
+                       guint status;
+                       guint workers_count;
+                       guint scanners_count;
+                       guint workers_hb_lost;
+               } health;
        } reply;
 };