Module: sip-router
Branch: andrei/counters
Commit: be186dac78d509f1a36133cbcde1204b613733f6
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=be186da…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)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 */
Module: sip-router
Branch: andrei/counters
Commit: 1aca6a526b718c95eecdb86e17f7f0eeb7abf0bc
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1aca6a5…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Mon Aug 9 00:16:54 2010 +0200
tcp: enable tcp statistics
tcp statistics implemented using the counters api.
Enabled by default (unless compiles with -DNO_TCP_STATS).
E.g.:
$ sercmd cnt.grp_get_all tcp
{
con_reset: 4
con_timeout: 0
connect_failed: 6
connect_success: 1
established: 12
local_reject: 0
passive_open: 11
send_timeout: 0
sendq_full: 0
}
---
tcp_stats.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tcp_stats.h | 55 +++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 111 insertions(+), 9 deletions(-)
diff --git a/tcp_stats.c b/tcp_stats.c
new file mode 100644
index 0000000..e0a8fc0
--- /dev/null
+++ b/tcp_stats.c
@@ -0,0 +1,65 @@
+/*
+ * $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.
+ */
+/** tcp statistics.
+ * @file tcp_stats.c
+ * @ingroup: core
+ */
+/*
+ * History:
+ * --------
+ * 2010-08-08 initial version (andrei)
+*/
+
+#include "tcp_stats.h"
+#include "counters.h"
+
+struct tcp_counters_h tcp_cnts_h;
+
+/** intialize tcp statistics.
+ * Must be called before forking.
+ * @return < 0 on errror, 0 on success.
+ */
+int tcp_stats_init()
+{
+#define TCP_REG_COUNTER(name) \
+ 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);
+ return 0;
+error:
+ return -1;
+}
+
+
+void tcp_stats_destroy()
+{
+ /* do nothing */
+}
+
+
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
diff --git a/tcp_stats.h b/tcp_stats.h
index 67c1ddc..f39e2ec 100644
--- a/tcp_stats.h
+++ b/tcp_stats.h
@@ -27,6 +27,11 @@
#ifndef __tcp_stats_h
#define __tcp_stats_h
+/* enable tcp stats by default */
+#ifndef NO_TCP_STATS
+#define USE_TCP_STATS
+#endif
+
#ifndef USE_TCP_STATS
#define INIT_TCP_STATS() 0 /* success */
@@ -42,9 +47,28 @@
#else /* USE_TCP_STATS */
-#define INIT_TCP_STATS() 0 /* success */
+#include "counters.h"
-#define DESTROY_TCP_STATS()
+struct tcp_counters_h {
+ counter_handle_t established;
+ counter_handle_t passive_open;
+ counter_handle_t connect_success;
+ counter_handle_t connect_failed;
+ counter_handle_t local_reject;
+ counter_handle_t con_timeout;
+ counter_handle_t con_reset;
+ counter_handle_t send_timeout;
+ counter_handle_t sendq_full;
+};
+
+extern struct tcp_counters_h tcp_cnts_h;
+
+int tcp_stats_init();
+void tcp_stats_destroy();
+
+#define INIT_TCP_STATS() tcp_stats_init()
+
+#define DESTROY_TCP_STATS() tcp_stats_destroy()
/** called each time a new tcp connection is established.
@@ -54,36 +78,49 @@
* sent on the new connection and not immediately after accept() or
* connect()
*/
-#define TCP_STATS_ESTABLISHED(state)
+#define TCP_STATS_ESTABLISHED(state) \
+ do { \
+ counter_inc(tcp_cnts_h.established); \
+ if (state == S_CONN_ACCEPT) \
+ counter_inc(tcp_cnts_h.passive_open); \
+ else \
+ counter_inc(tcp_cnts_h.connect_success); \
+ }while(0)
/** called each time a new outgoing connection fails. */
-#define TCP_STATS_CONNECT_FAILED()
+#define TCP_STATS_CONNECT_FAILED() \
+ counter_inc(tcp_cnts_h.connect_failed)
/** called each time a new incoming connection is rejected.
* (accept() denied due to maximum number of TCP connections being exceeded)
*/
-#define TCP_STATS_LOCAL_REJECT()
+#define TCP_STATS_LOCAL_REJECT() \
+ counter_inc(tcp_cnts_h.local_reject)
/** called each time a connection lifetime expires.
* (the connection is closed for being idle for too long)
*/
-#define TCP_STATS_CON_TIMEOUT()
+#define TCP_STATS_CON_TIMEOUT() \
+ counter_inc(tcp_cnts_h.con_timeout)
/** called each time a TCP RST is received on an established connection. */
-#define TCP_STATS_CON_RESET()
+#define TCP_STATS_CON_RESET() \
+ counter_inc(tcp_cnts_h.con_reset)
/** called each time a send operation fails due to a timeout.
* FIXME: it works only in async mode (in sync. mode a send might timeout
* but the stats won't be increased).
*/
-#define TCP_STATS_SEND_TIMEOUT()
+#define TCP_STATS_SEND_TIMEOUT() \
+ counter_inc(tcp_cnts_h.send_timeout)
/** called each time a send fails due to the buffering capacity being exceeded.
* (used only in tcp async mode)
*/
-#define TCP_STATS_SENDQ_FULL()
+#define TCP_STATS_SENDQ_FULL() \
+ counter_inc(tcp_cnts_h.sendq_full)
#endif /* USE_TCP_STATS */
Module: sip-router
Branch: andrei/counters
Commit: efb487e2a47d7c714821d506b5efe8cf46d632a6
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=efb487e…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Sun Aug 8 19:36:48 2010 +0200
kcore stats: rewrote in terms of the counters api
Most of the original kamailio statistics functions and data types are now
wrappers over sr counters.
The only important usage difference is that sr counters are
uniquely identified by group and name (one can have counters with
the same name if they are in different groups), while kamailio
stats vars had unique names. This means that when using the
kamailio get_stat(name) the first counter matching that name will
be returned (in the future this kind of usage should be
obsoleted).
Removed functions (not needed):
get_stats_collector()
destroy_stats_collector()
Removed data types:
stats_collector
module_stats
New functions:
stats_support() - partially replaces get_stats_collector().
get_stat_name() - returns the name of a stat_var.
get_stat_module() - returns the module of a stat_var.
---
lib/kcore/kstats_wrapper.c | 105 ++++++++++++++++++
lib/kcore/kstats_wrapper.h | 171 ++++++++++++++++++++++++++++++
lib/kcore/statistics.c | 251 +-------------------------------------------
lib/kcore/statistics.h | 104 +------------------
4 files changed, 279 insertions(+), 352 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=efb…
Module: sip-router
Branch: andrei/counters
Commit: 388ac89f2cdc2ed6a411238fb9b8b17531557b33
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=388ac89…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Sun Aug 8 19:33:32 2010 +0200
sercmd: added command line completion for counters
Command line completion for counters groups and names, for all the
counters RPCs defined in the counters module.
---
utils/sercmd/sercmd.c | 317 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 316 insertions(+), 1 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=388…
Module: sip-router
Branch: andrei/counters
Commit: 4208dc00cf245559ed3152beace6084c7c6c4571
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4208dc0…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Sun Aug 8 18:41:30 2010 +0200
core: counters / statistics support
Efficient counters support (api).
Incrementing or adding a value to a defined counter is extremely
fast at the cost of slower reading (each process has its own
set of counters => no cacheline ping-pong and no expensive atomic
operations).
All counters must be defined before forking (in a module this
means from mod_init() or init_child(rank==PROC_INIT)).
A counter is uniquely identified by its group and its name
(and not only by its name like in kamailio stats).
Example (error checking skipped):
/* before forking, e.g. mod_init() */
counter_handle_t h;
/* declare the counter my_grp.foo */
counter_register(&h, "my_grp", "foo", 0, 0, 0, 0);
/* after forking */
counter_inc(h);
/* getting a counter value, knowing its group and name*/
counter_lookup(&h, "my_grp", "foo");
val = counter_get(h);
---
counters.c | 696 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
counters.h | 124 +++++++++++
main.c | 10 +-
3 files changed, 828 insertions(+), 2 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=420…