[sr-dev] git:andrei/counters: tcp: switched to counter arrays + more stats

Andrei Pelinescu-Onciul andrei at iptel.org
Mon Aug 9 17:11:23 CEST 2010


Module: sip-router
Branch: andrei/counters
Commit: 17ac58e824e44a298e9211a33089b99841f66217
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=17ac58e824e44a298e9211a33089b99841f66217

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Mon Aug  9 17:01:11 2010 +0200

tcp: switched to counter arrays + more stats

- use counters arrays
- added counters description/doc
- don't attempt to compile if tcp support or tcp stats support are
  disabled.
- more stats: current_opened_connections and
  current_write_queue_size.

---

 tcp_stats.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/tcp_stats.c b/tcp_stats.c
index e0a8fc0..dc2dd61 100644
--- a/tcp_stats.c
+++ b/tcp_stats.c
@@ -25,11 +25,77 @@
  *  2010-08-08  initial version (andrei)
 */
 
+#ifdef USE_TCP
 #include "tcp_stats.h"
+
+#ifdef USE_TCP_STATS
+
 #include "counters.h"
+#include "tcp_info.h"
 
 struct tcp_counters_h tcp_cnts_h;
 
+
+enum tcp_info_req { TCP_INFO_NONE, TCP_INFO_CONN_NO, TCP_INFO_WR_QUEUE_SZ };
+
+static counter_val_t tcp_info(counter_handle_t h, void* what);
+
+/* tcp counters definitions */
+counter_def_t tcp_cnt_defs[] =  {
+	{&tcp_cnts_h.established, "established", 0, 0, 0,
+		"incremented each time a tcp connection is established."},
+	{&tcp_cnts_h.passive_open, "passive_open", 0, 0, 0,
+		"total number of accepted connections (so far)."},
+	{&tcp_cnts_h.connect_success, "connect_success", 0, 0, 0,
+		"total number of successfully active opened connections"
+			" (successful connect()s)."},
+	{&tcp_cnts_h.connect_failed, "connect_failed", 0, 0, 0,
+		"number of failed active connection attempts."},
+	{&tcp_cnts_h.local_reject, "local_reject", 0, 0, 0,
+		"number of rejected incoming connections."},
+	{&tcp_cnts_h.con_timeout, "con_timeout", 0, 0, 0,
+		"total number of connections that did timeout (idle for too long)."},
+	{&tcp_cnts_h.con_reset, "con_reset", 0, 0, 0,
+		"total number of TCP_RSTs received on established connections."},
+	{&tcp_cnts_h.send_timeout, "send_timeout", 0, 0, 0,
+		"number of send attempts that failed due to a timeout"
+			"(note: works only in tcp async mode)."},
+	{&tcp_cnts_h.sendq_full, "sendq_full", 0, 0, 0,
+		"number of send attempts that failed because of exceeded buffering"
+			"capacity (send queue full, works only in tcp async mode)."},
+	{0, "current_opened_connections", 0,
+		tcp_info, (void*)(long)TCP_INFO_CONN_NO,
+		"number of currently opened connections."},
+	{0, "current_write_queue_size", 0,
+		tcp_info, (void*)(long)TCP_INFO_WR_QUEUE_SZ,
+		"current sum of all the connections write queue sizes."},
+	{0, 0, 0, 0, 0, 0 }
+};
+
+
+
+/** helper function for some stats (which are kept internally inside tcp).
+ */
+static counter_val_t tcp_info(counter_handle_t h, void* what)
+{
+	enum tcp_info_req w;
+	struct tcp_gen_info ti;
+
+	if (tcp_disable)
+		return 0;
+	w = (int)(long)what;
+	tcp_get_info(&ti);
+	switch(w) {
+		case TCP_INFO_CONN_NO:
+			return ti.tcp_connections_no;
+		case TCP_INFO_WR_QUEUE_SZ:
+			return ti.tcp_write_queued;
+		case TCP_INFO_NONE:
+			break;
+	};
+	return 0;
+}
+
 /** intialize tcp statistics.
  *  Must be called before forking.
  * @return < 0 on errror, 0 on success.
@@ -40,15 +106,8 @@ int tcp_stats_init()
 	if (counter_register(&tcp_cnts_h.name, "tcp", # name, 0, 0, 0, 0) < 0) \
 		goto error;
 
-	TCP_REG_COUNTER(established);
-	TCP_REG_COUNTER(passive_open);
-	TCP_REG_COUNTER(connect_success);
-	TCP_REG_COUNTER(connect_failed);
-	TCP_REG_COUNTER(local_reject);
-	TCP_REG_COUNTER(con_timeout);
-	TCP_REG_COUNTER(con_reset);
-	TCP_REG_COUNTER(send_timeout);
-	TCP_REG_COUNTER(sendq_full);
+	if (counter_register_array("tcp", tcp_cnt_defs) < 0)
+		goto error;
 	return 0;
 error:
 	return -1;
@@ -61,5 +120,6 @@ void tcp_stats_destroy()
 }
 
 
-
+#endif /* USE_TCP_STATS */
+#endif /* USE_TCP */
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */




More information about the sr-dev mailing list