Module: sip-router Branch: andrei/counters Commit: be186dac78d509f1a36133cbcde1204b613733f6 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=be186dac...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Mon Aug 9 00:35:04 2010 +0200
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 }
---
sctp_stats.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sctp_stats.h | 55 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 106 insertions(+), 11 deletions(-)
diff --git a/sctp_stats.c b/sctp_stats.c new file mode 100644 index 0000000..46b8a49 --- /dev/null +++ b/sctp_stats.c @@ -0,0 +1,62 @@ +/* + * $Id$ + * + * Copyright (C) 2010 iptelorg GmbH + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +/** sctp statistics. + * @file sctp_stats.c + * @ingroup: core (sctp) + */ +/* + * History: + * -------- + * 2010-08-09 initial version (andrei) +*/ + +#include "sctp_stats.h" +#include "counters.h" + +struct sctp_counters_h sctp_cnts_h; + +/** intialize sctp statistics. + * Must be called before forking. + * @return < 0 on errror, 0 on success. + */ +int sctp_stats_init() +{ +#define SCTP_REG_COUNTER(name) \ + if (counter_register(&sctp_cnts_h.name, "sctp", # name, 0, 0, 0, 0) < 0) \ + goto error; + + SCTP_REG_COUNTER(established); + SCTP_REG_COUNTER(connect_failed); + SCTP_REG_COUNTER(local_reject); + SCTP_REG_COUNTER(remote_shutdown); + SCTP_REG_COUNTER(assoc_shutdown); + SCTP_REG_COUNTER(comm_lost); + SCTP_REG_COUNTER(sendq_full); + SCTP_REG_COUNTER(send_force_retry); + return 0; +error: + return -1; +} + + +void sctp_stats_destroy() +{ + /* do nothing */ +} + +/* vi: set ts=4 sw=4 tw=79:ai:cindent: */ diff --git a/sctp_stats.h b/sctp_stats.h index 4f6efdb..1ce6f8d 100644 --- a/sctp_stats.h +++ b/sctp_stats.h @@ -28,6 +28,11 @@ #define __sctp_stats_h
+/* enable sctp stats by default */ +#ifndef NO_SCTP_STATS +#define USE_SCTP_STATS +#endif + #ifndef USE_SCTP_STATS
#define INIT_SCTP_STATS() 0 /* success */ @@ -45,59 +50,87 @@
#else /* USE_SCTP_STATS */
-#define INIT_SCTP_STATS() 0 /* success */ +#include "counters.h"
-#define DESTROY_SCTP_STATS() +struct sctp_counters_h { + counter_handle_t established; + counter_handle_t connect_failed; + counter_handle_t local_reject; + counter_handle_t remote_shutdown; + counter_handle_t assoc_shutdown; + counter_handle_t comm_lost; + counter_handle_t sendq_full; + counter_handle_t send_failed; + counter_handle_t send_force_retry; +}; + +extern struct sctp_counters_h sctp_cnts_h; + +int sctp_stats_init(); +void sctp_stats_destroy(); + +#define INIT_SCTP_STATS() sctp_stats_init() /* success */ + +#define DESTROY_SCTP_STATS() sctp_stats_destroy()
/** called each time a new sctp assoc. is established. * sctp notification: SCTP_COMM_UP. */ -#define SCTP_STATS_ESTABLISHED() +#define SCTP_STATS_ESTABLISHED() \ + counter_inc(sctp_cnts_h.established)
/** called each time a new outgoing connection/assoc open fails. * sctp notification: SCTP_CANT_STR_ASSOC */ -#define SCTP_STATS_CONNECT_FAILED() +#define SCTP_STATS_CONNECT_FAILED() \ + counter_inc(sctp_cnts_h.connect_failed)
/** called each time a new incoming connection is rejected. */ -#define SCTP_STATS_LOCAL_REJECT() +#define SCTP_STATS_LOCAL_REJECT() \ + counter_inc(sctp_cnts_h.local_reject)
/** called each time a connection is closed by the peer. * sctp notification: SCTP_SHUTDOWN_EVENT */ -#define SCTP_STATS_REMOTE_SHUTDOWN() +#define SCTP_STATS_REMOTE_SHUTDOWN() \ + counter_inc(sctp_cnts_h.remote_shutdown)
/** called each time a connection is shutdown. * sctp notification: SCTP_SHUTDOWN_COMP */ -#define SCTP_STATS_ASSOC_SHUTDOWN() +#define SCTP_STATS_ASSOC_SHUTDOWN() \ + counter_inc(sctp_cnts_h.assoc_shutdown)
/** called each time an established connection is closed due to some error. * sctp notification: SCTP_COMM_LOST */ -#define SCTP_STATS_COMM_LOST() +#define SCTP_STATS_COMM_LOST() \ + counter_inc(sctp_cnts_h.comm_lost)
/** called each time a send fails due to the buffering capacity being exceeded. * (send fails due to full kernel buffers) */ -#define SCTP_STATS_SENDQ_FULL() +#define SCTP_STATS_SENDQ_FULL() \ + counter_inc(sctp_cnts_h.sendq_full)
/** called each time a send fails. * (send fails for any reason except buffers full) * sctp notification: SCTP_SEND_FAILED */ -#define SCTP_STATS_SEND_FAILED() +#define SCTP_STATS_SEND_FAILED() \ + counter_inc(sctp_cnts_h.send_failed)
/** called each time a failed send is force-retried. * (possible only if sctp_send_retries is != 0) */ -#define SCTP_STATS_SEND_FORCE_RETRY() +#define SCTP_STATS_SEND_FORCE_RETRY() \ + counter_inc(sctp_cnts_h.send_force_retry)
#endif /* USE_SCTP_STATS */