From 1338ade65032e5aea4891694a61d8ee3d1c795e1 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Fri, 23 Apr 2010 23:25:34 +0200 Subject: [PATCH] Enhace connection statistics counters 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 | 45 ++++++++++++++++++++++++++++++++++++++++----- src/ngircd/conn.h | 6 +++++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index b95f25ef..0861b08b 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -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 ); diff --git a/src/ngircd/conn.h b/src/ngircd/conn.h index b94b10d5..f2ec823e 100644 --- a/src/ngircd/conn.h +++ b/src/ngircd/conn.h @@ -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 * * 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- */ -- 2.39.2