]> source.dussan.org Git - rspamd.git/commitdiff
Handle stats command.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Oct 2015 10:49:50 +0000 (11:49 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Oct 2015 10:49:50 +0000 (11:49 +0100)
src/libserver/rspamd_control.c
src/libutil/util.h
src/rspamd.h

index d1861a5afd4553bf825b521411da37a342cb6a58..3217798ced88a2df8ed34fc0dde27cdb0c1d6e2f 100644 (file)
@@ -334,12 +334,25 @@ rspamd_control_default_cmd_handler (gint fd,
 {
        struct rspamd_control_reply rep;
        gssize r;
+       struct rusage rusg;
 
        memset (&rep, 0, sizeof (rep));
        rep.type = cmd->type;
 
        switch (cmd->type) {
        case RSPAMD_CONTROL_STAT:
+               if (getrusage (RUSAGE_SELF, &rusg) == -1) {
+                       msg_err ("cannot get rusage stats: %s",
+                                       strerror (errno));
+               }
+               else {
+                       rep.reply.stat.utime = tv_to_double (&rusg.ru_utime);
+                       rep.reply.stat.systime = tv_to_double (&rusg.ru_stime);
+                       rep.reply.stat.maxrss = rusg.ru_maxrss;
+               }
+
+               rep.reply.stat.conns = cd->worker->nconns;
+               rep.reply.stat.utime = rspamd_get_calendar_ticks () - cd->worker->start_time;
                break;
        case RSPAMD_CONTROL_RELOAD:
                break;
index bf55f901f18837da396eb97f9e5ed4e99d3bed77..f39730b0f137faef34ed775caf3a48d9c07df18a 100644 (file)
@@ -193,6 +193,7 @@ void g_queue_clear (GQueue *queue);
                                                                           ((dbl) - (int)(dbl)) * 1000 * 1000; \
 } while (0)
 #define tv_to_msec(tv) ((tv)->tv_sec * 1000LLU + (tv)->tv_usec / 1000LLU)
+#define tv_to_double(tv) ((tv)->tv_sec + (tv)->tv_usec / 1e6f)
 #define ts_to_usec(ts) ((ts)->tv_sec * 1000000LLU +                                                    \
        (ts)->tv_nsec / 1000LLU)
 
index 88e8059472b838673d5d6889719b8c63072b88f2..970046eb57ded4faba40f6074e3f4596310d248e 100644 (file)
@@ -45,6 +45,8 @@
 struct rspamd_worker {
        pid_t pid;                      /**< pid of worker                                                                      */
        guint index;                    /**< index number                                                                       */
+       guint nconns;                   /**< current connections count                                          */
+       gdouble start_time;             /**< start time                                                                         */
        struct rspamd_main *srv;        /**< pointer to server structure                                        */
        GQuark type;                    /**< process type                                                                       */
        GHashTable *signal_events;      /**< signal events                                                                      */