kamailio.cfg: removed sample db_mode parameter for domain module
[sip-router] / sctp_stats.c
1 /* 
2  * $Id$
3  * 
4  * Copyright (C) 2010 iptelorg GmbH
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 /** sctp statistics.
19  * @file sctp_stats.c
20  * @ingroup:  core (sctp)
21  */
22 /*
23  * History:
24  * --------
25  *  2010-08-09  initial version (andrei)
26 */
27
28 #ifdef USE_SCTP
29
30 #include "sctp_stats.h"
31
32 #ifdef USE_SCTP_STATS
33
34 #include "counters.h"
35 #include "sctp_server.h"
36
37 struct sctp_counters_h sctp_cnts_h;
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
101 /** intialize sctp statistics.
102  *  Must be called before forking.
103  * @return < 0 on errror, 0 on success.
104  */
105 int sctp_stats_init()
106 {
107         if (counter_register_array("sctp", sctp_cnt_defs) < 0)
108                 goto error;
109         return 0;
110 error:
111         return -1;
112 }
113
114
115 void sctp_stats_destroy()
116 {
117         /* do nothing */
118 }
119
120 #endif /* USE_SCTP_STATS */
121 #endif /* USE_SCTP */
122
123 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */