4 * This module supplies statistics about the activity levels of your Citadel
5 * system. We didn't bother writing a reporting module, because there is
6 * already an excellent tool called MRTG (Multi Router Traffic Grapher) which
7 * is available at http://www.mrtg.org that can fetch data using external
8 * scripts. This module supplies data in the format expected by MRTG.
10 * Copyright (c) 1987-2009 by the citadel.org team
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include <sys/types.h>
37 #if TIME_WITH_SYS_TIME
38 # include <sys/time.h>
42 # include <sys/time.h>
51 #include <libcitadel.h>
54 #include "citserver.h"
65 #include "ctdl_module.h"
69 * Other functions call this one to output data in MRTG format
71 void mrtg_output(long value1, long value2) {
73 int uptime_days, uptime_hours, uptime_minutes;
75 uptime_t = time(NULL) - server_startup_time;
76 uptime_days = (int) (uptime_t / 86400L);
77 uptime_hours = (int) ((uptime_t % 86400L) / 3600L);
78 uptime_minutes = (int) ((uptime_t % 3600L) / 60L);
80 cprintf("%d ok\n", LISTING_FOLLOWS);
81 cprintf("%ld\n", value1);
82 cprintf("%ld\n", value2);
83 cprintf("%d days, %d hours, %d minutes\n",
84 uptime_days, uptime_hours, uptime_minutes);
85 cprintf("%s\n", config.c_humannode);
93 * Tell us how many users are online
95 void mrtg_users(void) {
96 long connected_users = 0;
97 long active_users = 0;
99 struct CitContext *cptr;
101 begin_critical_section(S_SESSION_TABLE);
102 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
104 if (cptr->internal_pgm == 0) {
107 if ( (time(NULL) - (cptr->lastidle)) < 900L) {
113 end_critical_section(S_SESSION_TABLE);
115 mrtg_output(connected_users, active_users);
120 * Volume of messages submitted
122 void mrtg_messages(void) {
123 mrtg_output(CitControl.MMhighest, 0L);
127 struct num_accounts {
133 * Helper function for mrtg_accounts()
135 void tally_account(struct ctdluser *EachUser, void *userdata)
137 struct num_accounts *n = (struct num_accounts *) userdata;
140 if ( (time(NULL) - EachUser->lastcall) <= 2592000 ) ++n->active;
145 * Number of accounts and active accounts
147 void mrtg_accounts(void) {
148 struct num_accounts n = {
153 ForEachUser(tally_account, (void *)&n );
154 mrtg_output(n.total, n.active);
159 * Fetch data for MRTG
161 void cmd_mrtg(char *argbuf) {
164 extract_token(which, argbuf, 0, '|', sizeof which);
166 if (!strcasecmp(which, "users")) {
169 else if (!strcasecmp(which, "messages")) {
172 else if (!strcasecmp(which, "accounts")) {
176 cprintf("%d Unrecognized keyword '%s'\n", ERROR + ILLEGAL_VALUE, which);
181 CTDL_MODULE_INIT(mrtg)
185 CtdlRegisterProtoHook(cmd_mrtg, "MRTG", "Supply stats to MRTG");
188 /* return our Subversion id for the Log */