Browse code

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.

Andrei Pelinescu-Onciul authored on 09/08/2010 15:01:11
Showing 1 changed files
... ...
@@ -25,11 +25,77 @@
25 25
  *  2010-08-08  initial version (andrei)
26 26
 */
27 27
 
28
+#ifdef USE_TCP
28 29
 #include "tcp_stats.h"
30
+
31
+#ifdef USE_TCP_STATS
32
+
29 33
 #include "counters.h"
34
+#include "tcp_info.h"
30 35
 
31 36
 struct tcp_counters_h tcp_cnts_h;
32 37
 
38
+
39
+enum tcp_info_req { TCP_INFO_NONE, TCP_INFO_CONN_NO, TCP_INFO_WR_QUEUE_SZ };
40
+
41
+static counter_val_t tcp_info(counter_handle_t h, void* what);
42
+
43
+/* tcp counters definitions */
44
+counter_def_t tcp_cnt_defs[] =  {
45
+	{&tcp_cnts_h.established, "established", 0, 0, 0,
46
+		"incremented each time a tcp connection is established."},
47
+	{&tcp_cnts_h.passive_open, "passive_open", 0, 0, 0,
48
+		"total number of accepted connections (so far)."},
49
+	{&tcp_cnts_h.connect_success, "connect_success", 0, 0, 0,
50
+		"total number of successfully active opened connections"
51
+			" (successful connect()s)."},
52
+	{&tcp_cnts_h.connect_failed, "connect_failed", 0, 0, 0,
53
+		"number of failed active connection attempts."},
54
+	{&tcp_cnts_h.local_reject, "local_reject", 0, 0, 0,
55
+		"number of rejected incoming connections."},
56
+	{&tcp_cnts_h.con_timeout, "con_timeout", 0, 0, 0,
57
+		"total number of connections that did timeout (idle for too long)."},
58
+	{&tcp_cnts_h.con_reset, "con_reset", 0, 0, 0,
59
+		"total number of TCP_RSTs received on established connections."},
60
+	{&tcp_cnts_h.send_timeout, "send_timeout", 0, 0, 0,
61
+		"number of send attempts that failed due to a timeout"
62
+			"(note: works only in tcp async mode)."},
63
+	{&tcp_cnts_h.sendq_full, "sendq_full", 0, 0, 0,
64
+		"number of send attempts that failed because of exceeded buffering"
65
+			"capacity (send queue full, works only in tcp async mode)."},
66
+	{0, "current_opened_connections", 0,
67
+		tcp_info, (void*)(long)TCP_INFO_CONN_NO,
68
+		"number of currently opened connections."},
69
+	{0, "current_write_queue_size", 0,
70
+		tcp_info, (void*)(long)TCP_INFO_WR_QUEUE_SZ,
71
+		"current sum of all the connections write queue sizes."},
72
+	{0, 0, 0, 0, 0, 0 }
73
+};
74
+
75
+
76
+
77
+/** helper function for some stats (which are kept internally inside tcp).
78
+ */
79
+static counter_val_t tcp_info(counter_handle_t h, void* what)
80
+{
81
+	enum tcp_info_req w;
82
+	struct tcp_gen_info ti;
83
+
84
+	if (tcp_disable)
85
+		return 0;
86
+	w = (int)(long)what;
87
+	tcp_get_info(&ti);
88
+	switch(w) {
89
+		case TCP_INFO_CONN_NO:
90
+			return ti.tcp_connections_no;
91
+		case TCP_INFO_WR_QUEUE_SZ:
92
+			return ti.tcp_write_queued;
93
+		case TCP_INFO_NONE:
94
+			break;
95
+	};
96
+	return 0;
97
+}
98
+
33 99
 /** intialize tcp statistics.
34 100
  *  Must be called before forking.
35 101
  * @return < 0 on errror, 0 on success.
... ...
@@ -40,15 +106,8 @@ int tcp_stats_init()
40 40
 	if (counter_register(&tcp_cnts_h.name, "tcp", # name, 0, 0, 0, 0) < 0) \
41 41
 		goto error;
42 42
 
43
-	TCP_REG_COUNTER(established);
44
-	TCP_REG_COUNTER(passive_open);
45
-	TCP_REG_COUNTER(connect_success);
46
-	TCP_REG_COUNTER(connect_failed);
47
-	TCP_REG_COUNTER(local_reject);
48
-	TCP_REG_COUNTER(con_timeout);
49
-	TCP_REG_COUNTER(con_reset);
50
-	TCP_REG_COUNTER(send_timeout);
51
-	TCP_REG_COUNTER(sendq_full);
43
+	if (counter_register_array("tcp", tcp_cnt_defs) < 0)
44
+		goto error;
52 45
 	return 0;
53 46
 error:
54 47
 	return -1;
... ...
@@ -61,5 +120,6 @@ void tcp_stats_destroy()
61 61
 }
62 62
 
63 63
 
64
-
64
+#endif /* USE_TCP_STATS */
65
+#endif /* USE_TCP */
65 66
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */