Browse code

sctp: enable statistics

sctp statistics implemented using the counters api.
Enabled by default (unless compiles with -DNO_SCTP_STATS).
E.g.:
$ sercmd cnt.grp_get_all sctp
{
assoc_shutdown: 1
comm_lost: 0
connect_failed: 1
established: 1
local_reject: 0
remote_shutdown: 1
send_force_retry: 0
sendq_full: 0
}

Andrei Pelinescu-Onciul authored on 08/08/2010 22:35:04
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,62 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2010 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/** sctp statistics.
18
+ * @file sctp_stats.c
19
+ * @ingroup:  core (sctp)
20
+ */
21
+/*
22
+ * History:
23
+ * --------
24
+ *  2010-08-09  initial version (andrei)
25
+*/
26
+
27
+#include "sctp_stats.h"
28
+#include "counters.h"
29
+
30
+struct sctp_counters_h sctp_cnts_h;
31
+
32
+/** intialize sctp statistics.
33
+ *  Must be called before forking.
34
+ * @return < 0 on errror, 0 on success.
35
+ */
36
+int sctp_stats_init()
37
+{
38
+#define SCTP_REG_COUNTER(name) \
39
+	if (counter_register(&sctp_cnts_h.name, "sctp", # name, 0, 0, 0, 0) < 0) \
40
+		goto error;
41
+
42
+	SCTP_REG_COUNTER(established);
43
+	SCTP_REG_COUNTER(connect_failed);
44
+	SCTP_REG_COUNTER(local_reject);
45
+	SCTP_REG_COUNTER(remote_shutdown);
46
+	SCTP_REG_COUNTER(assoc_shutdown);
47
+	SCTP_REG_COUNTER(comm_lost);
48
+	SCTP_REG_COUNTER(sendq_full);
49
+	SCTP_REG_COUNTER(send_force_retry);
50
+	return 0;
51
+error:
52
+	return -1;
53
+}
54
+
55
+
56
+void sctp_stats_destroy()
57
+{
58
+	/* do nothing */
59
+}
60
+
61
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -28,6 +28,11 @@
28 28
 #define __sctp_stats_h
29 29
 
30 30
 
31
+/* enable sctp stats by default */
32
+#ifndef NO_SCTP_STATS
33
+#define USE_SCTP_STATS
34
+#endif
35
+
31 36
 #ifndef USE_SCTP_STATS
32 37
 
33 38
 #define INIT_SCTP_STATS() 0 /* success */
... ...
@@ -45,59 +50,87 @@
45 45
 
46 46
 #else /* USE_SCTP_STATS */
47 47
 
48
-#define INIT_SCTP_STATS() 0 /* success */
48
+#include "counters.h"
49 49
 
50
-#define DESTROY_SCTP_STATS()
50
+struct sctp_counters_h {
51
+	counter_handle_t established;
52
+	counter_handle_t connect_failed;
53
+	counter_handle_t local_reject;
54
+	counter_handle_t remote_shutdown;
55
+	counter_handle_t assoc_shutdown;
56
+	counter_handle_t comm_lost;
57
+	counter_handle_t sendq_full;
58
+	counter_handle_t send_failed;
59
+	counter_handle_t send_force_retry;
60
+};
61
+
62
+extern struct sctp_counters_h sctp_cnts_h;
63
+
64
+int sctp_stats_init();
65
+void sctp_stats_destroy();
66
+
67
+#define INIT_SCTP_STATS() sctp_stats_init() /* success */
68
+
69
+#define DESTROY_SCTP_STATS() sctp_stats_destroy()
51 70
 
52 71
 
53 72
 /** called each time a new sctp assoc. is established.
54 73
  * sctp notification: SCTP_COMM_UP.
55 74
  */
56
-#define SCTP_STATS_ESTABLISHED()
75
+#define SCTP_STATS_ESTABLISHED() \
76
+	counter_inc(sctp_cnts_h.established)
57 77
 
58 78
 /** called each time a new outgoing connection/assoc open fails.
59 79
  *  sctp notification: SCTP_CANT_STR_ASSOC
60 80
  */
61
-#define SCTP_STATS_CONNECT_FAILED()
81
+#define SCTP_STATS_CONNECT_FAILED() \
82
+	counter_inc(sctp_cnts_h.connect_failed)
62 83
 
63 84
 /** called each time a new incoming connection is rejected.  */
64
-#define SCTP_STATS_LOCAL_REJECT()
85
+#define SCTP_STATS_LOCAL_REJECT() \
86
+	counter_inc(sctp_cnts_h.local_reject)
65 87
 
66 88
 
67 89
 /** called each time a connection is closed by the peer.
68 90
   * sctp notification: SCTP_SHUTDOWN_EVENT
69 91
   */
70
-#define SCTP_STATS_REMOTE_SHUTDOWN()
92
+#define SCTP_STATS_REMOTE_SHUTDOWN() \
93
+	counter_inc(sctp_cnts_h.remote_shutdown)
71 94
 
72 95
 
73 96
 /** called each time a connection is shutdown.
74 97
   * sctp notification: SCTP_SHUTDOWN_COMP
75 98
   */
76
-#define SCTP_STATS_ASSOC_SHUTDOWN()
99
+#define SCTP_STATS_ASSOC_SHUTDOWN() \
100
+	counter_inc(sctp_cnts_h.assoc_shutdown)
77 101
 
78 102
 
79 103
 /** called each time an established connection is closed due to some error.
80 104
   * sctp notification: SCTP_COMM_LOST
81 105
   */
82
-#define SCTP_STATS_COMM_LOST()
106
+#define SCTP_STATS_COMM_LOST() \
107
+	counter_inc(sctp_cnts_h.comm_lost)
83 108
 
84 109
 
85 110
 /** called each time a send fails due to the buffering capacity being exceeded.
86 111
   * (send fails due to full kernel buffers)
87 112
   */
88
-#define SCTP_STATS_SENDQ_FULL()
113
+#define SCTP_STATS_SENDQ_FULL() \
114
+	counter_inc(sctp_cnts_h.sendq_full)
89 115
 
90 116
 
91 117
 /** called each time a send fails.
92 118
   * (send fails for any reason except buffers full)
93 119
   * sctp notification: SCTP_SEND_FAILED
94 120
   */
95
-#define SCTP_STATS_SEND_FAILED()
121
+#define SCTP_STATS_SEND_FAILED() \
122
+	counter_inc(sctp_cnts_h.send_failed)
96 123
 
97 124
 /** called each time a failed send is force-retried.
98 125
   * (possible only if sctp_send_retries is != 0)
99 126
   */
100
-#define SCTP_STATS_SEND_FORCE_RETRY()
127
+#define SCTP_STATS_SEND_FORCE_RETRY() \
128
+	counter_inc(sctp_cnts_h.send_force_retry)
101 129
 
102 130
 #endif /* USE_SCTP_STATS */
103 131