* Added a module "serv_mrtg" which allows activity reporting to MRTG
authorArt Cancro <ajc@citadel.org>
Fri, 7 Jun 2002 03:22:13 +0000 (03:22 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 7 Jun 2002 03:22:13 +0000 (03:22 +0000)
  (http://www.mrtg.org) -- this will replace our stats program.

citadel/ChangeLog
citadel/Makefile.in
citadel/citserver.c
citadel/citserver.h
citadel/serv_mrtg.c [new file with mode: 0644]

index 5f54947c93220c3f08755843220ac7d979cce45d..2768183f4dc85ebd4fd3477f42564eac5a045df4 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 591.35  2002/06/07 03:22:13  ajc
+ * Added a module "serv_mrtg" which allows activity reporting to MRTG
+   (http://www.mrtg.org) -- this will replace our stats program.
+
  Revision 591.34  2002/06/02 16:42:17  error
  * Support for Ctrl-W to erase a word when editing or at a prompt
 
@@ -3688,4 +3692,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index d87b09a2af46acd8c9152b6e32c439eaef7b4478..5cb7aeebe799d43b0f9a7ed1e8e61c8b6c3439f5 100644 (file)
@@ -29,6 +29,7 @@ SERV_MODULES=modules/libchat.la modules/libvcard.la \
        modules/libupgrade.la \
        $(SMTP) \
        modules/libpop3.la \
+       modules/libmrtg.la \
        modules/libimap.la \
        modules/libnetwork.la \
        modules/libnetfilter.la \
@@ -77,7 +78,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c \
        client_crypto.c commands.c config.c control.c $(DATABASE) \
        dynloader.c file_ops.c housekeeping.c ipc_c_tcp.c locate_host.c \
        logging.c messages.c msgbase.c msgform.c \
-       policy.c readlog.c migratenet.c screen.c \
+       policy.c readlog.c migratenet.c screen.c serv_mrtg.c \
        room_ops.c rooms.c routines.c routines2.c serv_chat.c serv_crypto.c \
        serv_info.c serv_test.c setup.c snprintf.c stats.c serv_vcard.c \
        support.c sysdep.c tools.c user_ops.c userlist.c serv_expire.c \
@@ -85,7 +86,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c \
        auth.c chkpwd.c html.c vcard.c serv_upgrade.c serv_vandelay.c \
        serv_smtp.c serv_pop3.c internet_addressing.c parsedate.c genstamp.c \
        $(DOMAIN) clientsocket.c serv_inetcfg.c serv_rwho.c serv_bio.c \
-       client_passwords.c imap_misc.c serv_netfilter.c \
+       client_passwords.c imap_misc.c serv_netfilter.c serv_mrtg.c \
        serv_imap.c imap_tools.c imap_fetch.c imap_search.c imap_store.c \
        serv_network.c serv_pas2.c serv_ical.c md5.c server_main.c
 
@@ -154,6 +155,9 @@ modules/libtest.la: serv_test.lo libcitserver.la $(LIBTOOL)
 modules/libpop3.la: serv_pop3.lo md5.lo $(LIBTOOL) libcitserver.la
        $(LTSHARE) -o libpop3.la ../serv_pop3.lo ../md5.lo ../libcitserver.la
 
+modules/libmrtg.la: serv_mrtg.lo md5.lo $(LIBTOOL) libcitserver.la
+       $(LTSHARE) -o libmrtg.la ../serv_mrtg.lo ../md5.lo ../libcitserver.la
+
 modules/libinetcfg.la: serv_inetcfg.lo $(LIBTOOL) libcitserver.la
        $(LTSHARE) -o libinetcfg.la ../serv_inetcfg.lo ../libcitserver.la
 
index 5aea06c2baef5bc0f72f6747ab1c4e9ecc7b39a2..322386d69c3e65b993d0d701178069def621ef1e 100644 (file)
@@ -65,6 +65,7 @@ struct CitContext *ContextList = NULL;
 char *unique_session_numbers;
 int ScheduledShutdown = 0;
 int do_defrag = 0;
+time_t server_startup_time;
 
 /*
  * Various things that need to be initialized at startup
@@ -72,6 +73,8 @@ int do_defrag = 0;
 void master_startup(void) {
        struct timeval tv;
        
+       time(&server_startup_time);
+       
        lprintf(9, "master_startup() started\n");
        lprintf(7, "Opening databases\n");
        open_databases();
index 24531928043c0fa42aec6cfd747d75fbc998d023..ac55073bfa46276e3e1ebb96e761b1159bae7758 100644 (file)
@@ -54,4 +54,4 @@ enum {
 
 
 
-
+extern time_t server_startup_time;
diff --git a/citadel/serv_mrtg.c b/citadel/serv_mrtg.c
new file mode 100644 (file)
index 0000000..d74b95f
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * $Id$
+ *
+ * This module supplies statistics about the activity levels of your Citadel
+ * system.  We didn't bother writing a reporting module, because there is
+ * already an excellent tool called MRTG (Multi Router Traffic Grapher) which
+ * is available at http://www.mrtg.org that can fetch data using external
+ * scripts.  This module supplies data in the format expected by MRTG.
+ *
+ */
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <sys/wait.h>
+#include <string.h>
+#include <limits.h>
+#include "citadel.h"
+#include "server.h"
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "control.h"
+#include "dynloader.h"
+#include "room_ops.h"
+#include "user_ops.h"
+#include "policy.h"
+#include "database.h"
+#include "msgbase.h"
+#include "tools.h"
+
+
+/*
+ * Other functions call this one to output data in MRTG format
+ */
+void mrtg_output(long value1, long value2) {
+       time_t uptime_t;
+       int uptime_days, uptime_hours, uptime_minutes;
+       
+       uptime_t = time(NULL) - server_startup_time;
+       uptime_days = (int) (uptime_t / 86400L);
+       uptime_hours = (int) ((uptime_t % 86400L) / 3600L);
+       uptime_minutes = (int) ((uptime_t % 3600L) / 60L);
+
+       cprintf("%d ok\n", LISTING_FOLLOWS);
+       cprintf("%ld\n", value1);
+       cprintf("%ld\n", value2);
+       cprintf("%d days, %d hours, %d minutes\n",
+               uptime_days, uptime_hours, uptime_minutes);
+       cprintf("%s\n", config.c_humannode);
+       cprintf("000\n");
+}
+
+
+
+
+/*
+ * Tell us how many users are online
+ */
+void mrtg_users(void) {
+       long connected_users = 0;
+       long active_users = 0;
+       
+       struct CitContext *cptr;
+
+        for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
+
+               ++connected_users;
+
+               if ( (time(NULL) - (cptr->lastidle)) < 900L) {
+                       ++active_users;
+               }
+
+       }
+
+       mrtg_output(connected_users, active_users);
+}
+
+
+/*
+ * Volume of messages submitted
+ */
+void mrtg_messages(void) {
+       mrtg_output(CitControl.MMhighest, 0L);
+}
+
+
+/*
+ * Fetch data for MRTG
+ */
+void cmd_mrtg(char *argbuf) {
+       char which[SIZ];
+
+       extract(which, argbuf, 0);
+
+       if (!strcasecmp(which, "users")) {
+               mrtg_users();
+       }
+       if (!strcasecmp(which, "messages")) {
+               mrtg_messages();
+       }
+       else {
+               cprintf("%d Unrecognized keyword '%s'\n",
+                       ERROR+ILLEGAL_VALUE, which);
+       }
+}
+
+
+char *Dynamic_Module_Init(void)
+{
+        CtdlRegisterProtoHook(cmd_mrtg, "MRTG", "Supply stats to MRTG");
+        return "$Id$";
+}