]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/mrtg/serv_mrtg.c
Added a serv_mrtg mode to tally total accounts and active accounts.
[citadel.git] / citadel / modules / mrtg / serv_mrtg.c
index dab0ab7b809ad90f33eaba51e503b37d08d85af6..8eb9c53fdfe39faa1569da14dc1cf05fd80c4191 100644 (file)
@@ -83,6 +83,7 @@ void mrtg_users(void) {
        
        struct CitContext *cptr;
 
+       begin_critical_section(S_SESSION_TABLE);
         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
 
                if (cptr->internal_pgm == 0) {
@@ -94,7 +95,8 @@ void mrtg_users(void) {
                }
 
        }
-
+       end_critical_section(S_SESSION_TABLE);
+       
        mrtg_output(connected_users, active_users);
 }
 
@@ -107,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
  */
@@ -121,17 +154,22 @@ 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);
        }
 }
 
 
 CTDL_MODULE_INIT(mrtg)
 {
-        CtdlRegisterProtoHook(cmd_mrtg, "MRTG", "Supply stats to MRTG");
-
+       if (!threading)
+       {
+               CtdlRegisterProtoHook(cmd_mrtg, "MRTG", "Supply stats to MRTG");
+       }
+       
        /* return our Subversion id for the Log */
         return "$Id$";
 }