|
@@ -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: */
|