]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Enhace connection statistics counters
authorAlexander Barton <alex@barton.de>
Fri, 23 Apr 2010 21:25:34 +0000 (23:25 +0200)
committerAlexander Barton <alex@barton.de>
Fri, 23 Apr 2010 21:25:34 +0000 (23:25 +0200)
This patch enables ngIRCd to count the highest maximum simultaneous
connections and all the connections accepted since startup.

New functions:
- Conn_Count(): get current connections
- Conn_CountMax(): maximum simultaneous connections
- Conn_CountAccepted(): number of connections accepted

src/ngircd/conn.c
src/ngircd/conn.h

index b95f25ef61a47e6f720e66921a0a266298e77243..0861b08b9e10f38fbd754be58cc8bf44a4b249aa 100644 (file)
@@ -95,10 +95,12 @@ static bool Init_Socket PARAMS(( int Sock ));
 static void New_Server PARAMS(( int Server, ng_ipaddr_t *dest ));
 static void Simple_Message PARAMS(( int Sock, const char *Msg ));
 static int NewListener PARAMS(( const char *listen_addr, UINT16 Port ));
+static void Account_Connection PARAMS((void));
+
 
 static array My_Listeners;
 static array My_ConnArray;
-static size_t NumConnections;
+static size_t NumConnections, NumConnectionsMax, NumConnectionsAccepted;
 
 #ifdef TCPWRAP
 int allow_severity = LOG_INFO;
@@ -388,7 +390,8 @@ Conn_Init( void )
        for (i = 0; i < Pool_Size; i++)
                Init_Conn_Struct(i);
 
-       /* Global write counter */
+       /* Initialize global counters (required after RESTART command!) */
+       NumConnections = NumConnectionsMax = NumConnectionsAccepted = 0;
        WCounter = 0;
 } /* Conn_Init */
 
@@ -1102,6 +1105,27 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie
 } /* Conn_Close */
 
 
+GLOBAL long
+Conn_Count(void)
+{
+       return NumConnections;
+} /* Conn_Count */
+
+
+GLOBAL long
+Conn_CountMax(void)
+{
+       return NumConnectionsMax;
+} /* Conn_CountMax */
+
+
+GLOBAL long
+Conn_CountAccepted(void)
+{
+       return NumConnectionsAccepted;
+} /* Conn_CountAccepted */
+
+
 GLOBAL void
 Conn_SyncServerStruct( void )
 {
@@ -1242,6 +1266,7 @@ New_Connection(int Sock)
                Log(LOG_CRIT, "Can't accept connection: %s!", strerror(errno));
                return -1;
        }
+       NumConnectionsAccepted++;
 
        if (!ng_ipaddr_tostr_r(&new_addr, ip_str)) {
                Log(LOG_CRIT, "fd %d: Can't convert IP address!", new_sock);
@@ -1361,12 +1386,22 @@ New_Connection(int Sock)
         * If there are results earlier, the delay is aborted. */
        Conn_SetPenalty(new_sock, 4);
 
-       NumConnections++;
-       LogDebug("Total number of connections now %ld.", NumConnections);
+       Account_Connection();
        return new_sock;
 } /* New_Connection */
 
 
+static void
+Account_Connection(void)
+{
+       NumConnections++;
+       if (NumConnections > NumConnectionsMax)
+               NumConnectionsMax = NumConnections;
+       LogDebug("Total number of connections now %lu (max %lu).",
+                NumConnections, NumConnectionsMax);
+} /* Account_Connection */
+
+
 static CONN_ID
 Socket2Index( int Sock )
 {
@@ -1806,7 +1841,7 @@ New_Server( int Server , ng_ipaddr_t *dest)
        }
 
        /* Conn_Close() decrements this counter again */
-       NumConnections++;
+       Account_Connection();
        Client_SetIntroducer( c, c );
        Client_SetToken( c, TOKEN_OUTBOUND );
 
index b94b10d5e513a8abccaa8c9d62c16366913be60c..f2ec823ea6ee25bed5af38149263cbd228a6a2f7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2009 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2010 Alexander Barton <alex@barton.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -122,5 +122,9 @@ static inline bool Conn_UsesSSL(UNUSED CONN_ID Idx) { return false; }
 #endif
 #endif
 
+GLOBAL long Conn_Count PARAMS((void));
+GLOBAL long Conn_CountMax PARAMS((void));
+GLOBAL long Conn_CountAccepted PARAMS((void));
+
 
 /* -eof- */