aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libserver/rspamd_control.c52
-rw-r--r--src/libserver/rspamd_control.h5
2 files changed, 54 insertions, 3 deletions
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 8d9067053..24d527025 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -33,6 +33,10 @@ static struct timeval io_timeout = {
.tv_sec = 30,
.tv_usec = 0
};
+static struct timeval worker_io_timeout = {
+ .tv_sec = 0,
+ .tv_usec = 500000
+};
struct rspamd_control_session;
@@ -141,6 +145,50 @@ rspamd_control_connection_close (struct rspamd_control_session *session)
}
static void
+rspamd_control_write_reply (struct rspamd_control_session *session)
+{
+ ucl_object_t *rep, *cur;
+ struct rspamd_control_reply_elt *elt;
+ gchar tmpbuf[64];
+
+ rep = ucl_object_typed_new (UCL_OBJECT);
+
+ DL_FOREACH (session->replies, elt) {
+ rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "%p", elt->wrk->pid);
+ cur = ucl_object_typed_new (UCL_OBJECT);
+
+ ucl_object_insert_key (cur, ucl_object_fromstring (g_quark_to_string (
+ elt->wrk->type)), "type", 0, false);
+
+ switch (elt->session->cmd.type) {
+ case RSPAMD_CONTROL_STAT:
+ ucl_object_insert_key (cur, ucl_object_fromint (
+ elt->reply.reply.stat.conns), "conns", 0, false);
+ ucl_object_insert_key (cur, ucl_object_fromdouble (
+ elt->reply.reply.stat.utime), "utime", 0, false);
+ ucl_object_insert_key (cur, ucl_object_fromdouble (
+ elt->reply.reply.stat.systime), "systime", 0, false);
+ ucl_object_insert_key (cur, ucl_object_fromdouble (
+ elt->reply.reply.stat.uptime), "uptime", 0, false);
+ ucl_object_insert_key (cur, ucl_object_fromint (
+ elt->reply.reply.stat.maxrss), "maxrss", 0, false);
+ break;
+ case RSPAMD_CONTROL_RELOAD:
+ ucl_object_insert_key (cur, ucl_object_fromint (
+ elt->reply.reply.reload.status), "status", 0, false);
+ break;
+ default:
+ break;
+ }
+
+ ucl_object_insert_key (rep, cur, tmpbuf, 0, true);
+ }
+
+ rspamd_control_send_ucl (session, rep);
+ ucl_object_unref (rep);
+}
+
+static void
rspamd_control_wrk_io (gint fd, short what, gpointer ud)
{
struct rspamd_control_reply_elt *elt = ud;
@@ -155,7 +203,7 @@ rspamd_control_wrk_io (gint fd, short what, gpointer ud)
event_del (&elt->io_ev);
if (elt->session->replies_remain == 0) {
- /* TODO: add reply logic */
+ rspamd_control_write_reply (elt->session);
rspamd_control_connection_close (elt->session);
}
}
@@ -229,7 +277,7 @@ rspamd_control_finish_hadler (struct rspamd_http_connection *conn,
rep_elt);
event_base_set (session->rspamd_main->ev_base,
&rep_elt->io_ev);
- event_add (&rep_elt->io_ev, &io_timeout);
+ event_add (&rep_elt->io_ev, &worker_io_timeout);
DL_APPEND (session->replies, rep_elt);
session->replies_remain ++;
diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h
index 2863f2988..09143c6f8 100644
--- a/src/libserver/rspamd_control.h
+++ b/src/libserver/rspamd_control.h
@@ -53,7 +53,10 @@ struct rspamd_control_reply {
union {
struct {
guint conns;
- guint64 uptime;
+ gdouble uptime;
+ gdouble utime;
+ gdouble systime;
+ gulong maxrss;
} stat;
struct {
guint status;