]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats plugin: Added stats_refresh and stats_track_cmds settings.
authorTimo Sirainen <tss@iki.fi>
Thu, 1 Sep 2011 03:52:43 +0000 (06:52 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 1 Sep 2011 03:52:43 +0000 (06:52 +0300)
The stats plugin is enabled only when refresh is set to non-zero. The
imap_stats plugin tracks commands only when stats_track_cmds=yes.

src/plugins/imap-stats/imap-stats-plugin.c
src/plugins/stats/Makefile.am
src/plugins/stats/stats-plugin.c
src/plugins/stats/stats-plugin.h

index bd6240c6b382e5843563479b5e5f65f2b721f760..54a5b7001f3ad328385d089289c82eb677c099c2 100644 (file)
@@ -30,7 +30,7 @@ static void stats_command_pre(struct client_command_context *cmd)
        struct stats_client_command *scmd;
        static unsigned int stats_cmd_id_counter = 0;
 
-       if (suser == NULL)
+       if (suser == NULL || !suser->track_commands)
                return;
 
        scmd = IMAP_STATS_IMAP_CONTEXT(cmd);
index 32bf8fd6f7737cc228cfacdfe401034595300b73..e7a46d5de0c9b0bdbc8a52d1ea0c9d64d5350222 100644 (file)
@@ -1,5 +1,6 @@
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib \
+       -I$(top_srcdir)/src/lib-settings \
        -I$(top_srcdir)/src/lib-mail \
        -I$(top_srcdir)/src/lib-index \
        -I$(top_srcdir)/src/lib-storage
index 43bd3bdd88ad572ee4b0b5a37fa1694c4fe7bc7e..cbce6f5634c90d85201ec2ef4f8e19e0245e9ed6 100644 (file)
@@ -7,6 +7,7 @@
 #include "llist.h"
 #include "str.h"
 #include "time-util.h"
+#include "settings-parser.h"
 #include "stats-connection.h"
 #include "stats-plugin.h"
 
@@ -16,8 +17,6 @@
 #define STATS_CONTEXT(obj) \
        MODULE_CONTEXT(obj, stats_storage_module)
 
-/* Refresh session every 10 seconds, if anything has changed */
-#define SESSION_STATS_REFRESH_SECS 10
 /* If session isn't refreshed every 15 minutes, it's dropped.
    Must be smaller than MAIL_SESSION_IDLE_TIMEOUT_MSECS in stats server */
 #define SESSION_STATS_FORCE_REFRESH_SECS (5*60)
@@ -374,13 +373,13 @@ static void stats_io_deactivate(void *context)
                stats_add_session(user);
 
        last_update_secs = ioloop_time - suser->last_session_update;
-       if (last_update_secs >= SESSION_STATS_REFRESH_SECS) {
+       if (last_update_secs >= suser->refresh_secs) {
                if (stats_global_user != NULL)
                        stats_add_session(user);
                session_stats_refresh(user);
        } else if (suser->to_stats_timeout == NULL) {
                suser->to_stats_timeout =
-                       timeout_add(SESSION_STATS_REFRESH_SECS*1000,
+                       timeout_add(suser->refresh_secs*1000,
                                    session_stats_refresh_timeout, user);
        }
 }
@@ -420,7 +419,8 @@ static void stats_user_created(struct mail_user *user)
                io_loop_get_current_context(current_ioloop);
        struct stats_user *suser;
        struct mail_user_vfuncs *v = user->vlast;
-       const char *path;
+       const char *path, *str, *error;
+       unsigned int refresh_secs;
 
        if (ioloop_ctx == NULL) {
                /* we're probably running some test program, or at least
@@ -433,6 +433,17 @@ static void stats_user_created(struct mail_user *user)
                return;
        }
 
+       /* get refresh time */
+       str = mail_user_plugin_getenv(user, "stats_refresh");
+       if (str == NULL)
+               return;
+       if (settings_get_time(str, &refresh_secs, &error) < 0) {
+               i_error("stats: Invalid stats_refresh setting: %s", error);
+               return;
+       }
+       if (refresh_secs == 0)
+               return;
+
        if (global_stats_conn == NULL) {
                path = t_strconcat(user->set->base_dir,
                                   "/"MAIL_STATS_SOCKET_NAME, NULL);
@@ -456,6 +467,11 @@ static void stats_user_created(struct mail_user *user)
        user->vlast = &suser->module_ctx.super;
        user->v.deinit = stats_user_deinit;
 
+       suser->refresh_secs = refresh_secs;
+       str = mail_user_plugin_getenv(user, "stats_track_cmds");
+       if (str != NULL && strcmp(str, "yes") == 0)
+               suser->track_commands = TRUE;
+
        suser->stats_conn = global_stats_conn;
        guid_128_generate(suser->session_guid);
        suser->last_session_update = ioloop_time;
index 8f46977a716881dd43b5b08d92a8797b7434f40e..8b8fa697b8fd9367858654e2e87a0863a3b78bbb 100644 (file)
@@ -28,6 +28,9 @@ struct stats_user {
        struct stats_connection *stats_conn;
        guid_128_t session_guid;
 
+       unsigned int refresh_secs;
+       bool track_commands;
+
        /* current session statistics */
        struct mail_stats session_stats;
        /* stats before calling IO callback. after IO callback this value is