Browse code

sctp: switched to counter arrays + more stats

- use counters arrays
- added counters descriptions
- don't attempt to compile if sctp support or sctp stats support
are disabled
- more stats: current_opened_connections and
current_tracked_connections.

Andrei Pelinescu-Onciul authored on 09/08/2010 15:04:41
Showing 1 changed files
... ...
@@ -25,29 +25,87 @@
25 25
  *  2010-08-09  initial version (andrei)
26 26
 */
27 27
 
28
+#ifdef USE_SCTP
29
+
28 30
 #include "sctp_stats.h"
31
+
32
+#ifdef USE_SCTP_STATS
33
+
29 34
 #include "counters.h"
35
+#include "sctp_server.h"
30 36
 
31 37
 struct sctp_counters_h sctp_cnts_h;
32 38
 
39
+
40
+enum sctp_info_req { SCTP_INFO_NONE, SCTP_INFO_CONN_NO, SCTP_INFO_TRACKED_NO };
41
+static counter_val_t sctp_info(counter_handle_t h, void* what);
42
+
43
+
44
+
45
+/* sctp counters definitions */
46
+counter_def_t sctp_cnt_defs[] =  {
47
+	{&sctp_cnts_h.established, "established", 0, 0, 0,
48
+		"incremented each time a new association is established."},
49
+	{&sctp_cnts_h.connect_failed, "connect_failed", 0, 0, 0,
50
+		"incremented each time a new outgoing connection fails."},
51
+	{&sctp_cnts_h.local_reject, "local_reject", 0, 0, 0,
52
+		"number of rejected incoming connections."},
53
+	{&sctp_cnts_h.remote_shutdown, "remote_shutdown", 0, 0, 0,
54
+		"incremented each time an association is closed by the peer."},
55
+	{&sctp_cnts_h.assoc_shutdown, "assoc_shutdown", 0, 0, 0,
56
+		"incremented each time an association is shutdown."},
57
+	{&sctp_cnts_h.comm_lost, "comm_lost", 0, 0, 0,
58
+		"incremented each time an established connection is close due to"
59
+			"some error."},
60
+	{&sctp_cnts_h.sendq_full, "sendq_full", 0, 0, 0,
61
+		"number of failed send attempt due to exceeded buffering capacity"
62
+	    " (full kernel buffers)."},
63
+	{&sctp_cnts_h.send_failed, "send_failed", 0, 0, 0,
64
+		"number of failed send attempt for any reason except full buffers."},
65
+	{&sctp_cnts_h.send_force_retry, "send_force_retry", 0, 0, 0,
66
+		"incremented each time a failed send is force-retried"
67
+			"(possible only if sctp_send_retries ! = 0"},
68
+	{0, "current_opened_connections", 0,
69
+		sctp_info, (void*)(long)SCTP_INFO_CONN_NO,
70
+		"number of currently opened associations."},
71
+	{0, "current_tracked_connections", 0,
72
+		sctp_info, (void*)(long)SCTP_INFO_TRACKED_NO,
73
+		"number of currently tracked associations."},
74
+	{0, 0, 0, 0, 0, 0 }
75
+};
76
+
77
+
78
+
79
+/** helper function for some stats (which are kept internally inside sctp).
80
+ */
81
+static counter_val_t sctp_info(counter_handle_t h, void* what)
82
+{
83
+	enum sctp_info_req w;
84
+	struct sctp_gen_info i;
85
+
86
+	if (sctp_disable)
87
+		return 0;
88
+	w = (int)(long)what;
89
+	sctp_get_info(&i);
90
+	switch(w) {
91
+		case SCTP_INFO_CONN_NO:
92
+			return i.sctp_connections_no;
93
+		case SCTP_INFO_TRACKED_NO:
94
+			return i.sctp_tracked_no;
95
+		case SCTP_INFO_NONE:
96
+			break;
97
+	};
98
+	return 0;
99
+}
100
+
33 101
 /** intialize sctp statistics.
34 102
  *  Must be called before forking.
35 103
  * @return < 0 on errror, 0 on success.
36 104
  */
37 105
 int sctp_stats_init()
38 106
 {
39
-#define SCTP_REG_COUNTER(name) \
40
-	if (counter_register(&sctp_cnts_h.name, "sctp", # name, 0, 0, 0, 0) < 0) \
107
+	if (counter_register_array("sctp", sctp_cnt_defs) < 0)
41 108
 		goto error;
42
-
43
-	SCTP_REG_COUNTER(established);
44
-	SCTP_REG_COUNTER(connect_failed);
45
-	SCTP_REG_COUNTER(local_reject);
46
-	SCTP_REG_COUNTER(remote_shutdown);
47
-	SCTP_REG_COUNTER(assoc_shutdown);
48
-	SCTP_REG_COUNTER(comm_lost);
49
-	SCTP_REG_COUNTER(sendq_full);
50
-	SCTP_REG_COUNTER(send_force_retry);
51 109
 	return 0;
52 110
 error:
53 111
 	return -1;
... ...
@@ -59,4 +117,7 @@ void sctp_stats_destroy()
59 117
 	/* do nothing */
60 118
 }
61 119
 
120
+#endif /* USE_SCTP_STATS */
121
+#endif /* USE_SCTP */
122
+
62 123
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */