Mercurial > dovecot > core-2.2
changeset 13349:ec6d171a54bd
stats plugin: Added stats_refresh and stats_track_cmds settings.
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.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 01 Sep 2011 06:52:43 +0300 |
parents | fafbd108008c |
children | f77ee6f0c42a |
files | 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 |
diffstat | 4 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/imap-stats/imap-stats-plugin.c Thu Sep 01 06:36:34 2011 +0300 +++ b/src/plugins/imap-stats/imap-stats-plugin.c Thu Sep 01 06:52:43 2011 +0300 @@ -30,7 +30,7 @@ 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);
--- a/src/plugins/stats/Makefile.am Thu Sep 01 06:36:34 2011 +0300 +++ b/src/plugins/stats/Makefile.am Thu Sep 01 06:52:43 2011 +0300 @@ -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
--- a/src/plugins/stats/stats-plugin.c Thu Sep 01 06:36:34 2011 +0300 +++ b/src/plugins/stats/stats-plugin.c Thu Sep 01 06:52:43 2011 +0300 @@ -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 @@ 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 @@ 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 @@ 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 @@ 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;
--- a/src/plugins/stats/stats-plugin.h Thu Sep 01 06:36:34 2011 +0300 +++ b/src/plugins/stats/stats-plugin.h Thu Sep 01 06:52:43 2011 +0300 @@ -28,6 +28,9 @@ 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