summaryrefslogtreecommitdiffstats
path: root/src/plugins/old-stats/stats-plugin.h
blob: dedcfbd176c8069295f81d518fbfd49668eae89d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef STATS_PLUGIN_H
#define STATS_PLUGIN_H

#include "module-context.h"
#include "mail-user.h"
#include "mail-storage-private.h"

#define STATS_USER_CONTEXT(obj) \
	MODULE_CONTEXT(obj, stats_user_module)

#define STATS_USER_CONTEXT_REQUIRE(obj) \
	MODULE_CONTEXT_REQUIRE(obj, stats_user_module)

struct stats_user {
	union mail_user_module_context module_ctx;

	struct ioloop_context *ioloop_ctx;
	struct stats_connection *stats_conn;
	const char *stats_session_id;
	bool stats_connected;

	unsigned int refresh_secs;
	bool track_commands;
	unsigned int refresh_check_counter;

	/* current session statistics */
	struct stats *session_stats;
	/* cumulative trans_stats for all already freed transactions. */
	struct mailbox_transaction_stats finished_transaction_stats;
	/* stats before calling IO callback. after IO callback this value is
	   compared to current stats to see the difference */
	struct stats *pre_io_stats;

	time_t last_session_update;
	struct timeout *to_stats_timeout;
	/* stats that were last sent to stats server */
	struct stats *last_sent_session_stats;
	bool session_sent_duplicate;

	/* list of all currently existing transactions for this user */
	struct stats_transaction_context *transactions;
};

struct stats_transaction_context {
	union mailbox_transaction_module_context module_ctx;

	struct stats_transaction_context *prev, *next;
	struct mailbox_transaction_context *trans;

	struct mailbox_transaction_stats prev_stats;
};

extern MODULE_CONTEXT_DEFINE(stats_user_module, &mail_user_module_register);
extern MODULE_CONTEXT_DEFINE(stats_storage_module, &mail_storage_module_register);

void old_stats_plugin_init(struct module *module);
void old_stats_plugin_preinit(void);
void old_stats_plugin_deinit(void);

#endif