From 3e8fdc8192b85bb7009405e6adef5e4b337b3a8e Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 25 Jun 2008 21:08:59 +0000 Subject: [PATCH] Added a serv_mrtg mode to tally total accounts and active accounts. This will be useful for graphing site membership over long periods of time. --- citadel/modules/mrtg/serv_mrtg.c | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/citadel/modules/mrtg/serv_mrtg.c b/citadel/modules/mrtg/serv_mrtg.c index 666e04a41..8eb9c53fd 100644 --- a/citadel/modules/mrtg/serv_mrtg.c +++ b/citadel/modules/mrtg/serv_mrtg.c @@ -109,6 +109,37 @@ void mrtg_messages(void) { } +struct num_accounts { + long total; + long active; +}; + +/* + * Helper function for mrtg_accounts() + */ +void tally_account(struct ctdluser *EachUser, void *userdata) +{ + struct num_accounts *n = (struct num_accounts *) userdata; + + ++n->total; + if ( (time(NULL) - EachUser->lastcall) <= 2592000 ) ++n->active; +} + + +/* + * Number of accounts and active accounts + */ +void mrtg_accounts(void) { + struct num_accounts n = { + 0, + 0 + }; + + ForEachUser(tally_account, (void *)&n ); + mrtg_output(n.total, n.active); +} + + /* * Fetch data for MRTG */ @@ -123,9 +154,11 @@ void cmd_mrtg(char *argbuf) { else if (!strcasecmp(which, "messages")) { mrtg_messages(); } + else if (!strcasecmp(which, "accounts")) { + mrtg_accounts(); + } else { - cprintf("%d Unrecognized keyword '%s'\n", - ERROR + ILLEGAL_VALUE, which); + cprintf("%d Unrecognized keyword '%s'\n", ERROR + ILLEGAL_VALUE, which); } } -- 2.30.2