aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-08-18 18:39:53 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-08-18 18:39:53 +0200
commitf416463a3c4fa3d94d8f8c7cdcfb04123fbee994 (patch)
tree967d98c2ed74747129d52ada3992a23d186a18c0
parent918be5133883b0d6aaaf08046d39e91396740999 (diff)
client: First round of statistics in the pcap client
Count certain events that can help to understand what is going on. This includes OOM, failure to queues. Change-Id: I4a2dad32afb577822c7181d2813ea5a7e693c704
-rw-r--r--include/osmo-pcap/osmo_pcap_client.h15
-rw-r--r--src/osmo_client_main.c24
-rw-r--r--src/osmo_client_network.c9
3 files changed, 46 insertions, 2 deletions
diff --git a/include/osmo-pcap/osmo_pcap_client.h b/include/osmo-pcap/osmo_pcap_client.h
index 30b55ee..3cc3080 100644
--- a/include/osmo-pcap/osmo_pcap_client.h
+++ b/include/osmo-pcap/osmo_pcap_client.h
@@ -1,7 +1,7 @@
/*
* osmo-pcap-client code
*
- * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2011-2016 by Holger Hans Peter Freyther <holger@moiji-mobile.com>
* (C) 2011 by On-Waves
* All Rights Reserved
*
@@ -27,6 +27,16 @@
#include <osmocom/core/timer.h>
#include <osmocom/core/write_queue.h>
+struct rate_ctr_group;
+
+enum {
+ CLIENT_CTR_CONNECT,
+ CLIENT_CTR_BYTES,
+ CLIENT_CTR_PKTS,
+ CLIENT_CTR_2BIG,
+ CLIENT_CTR_NOMEM,
+ CLIENT_CTR_QERR,
+};
struct osmo_pcap_client {
char *device;
@@ -43,6 +53,9 @@ struct osmo_pcap_client {
int srv_port;
struct osmo_wqueue wqueue;
struct osmo_timer_list timer;
+
+ /* statistics */
+ struct rate_ctr_group *ctrg;
};
extern struct osmo_pcap_client *pcap_client;
diff --git a/src/osmo_client_main.c b/src/osmo_client_main.c
index db43ca6..945a871 100644
--- a/src/osmo_client_main.c
+++ b/src/osmo_client_main.c
@@ -52,6 +52,24 @@ struct osmo_pcap_client *pcap_client;
extern void *tall_msgb_ctx;
extern void *tall_ctr_ctx;
+
+static const struct rate_ctr_desc pcap_client_ctr_desc[] = {
+ [CLIENT_CTR_CONNECT] = { "server.connect", "Connects to the server" },
+ [CLIENT_CTR_BYTES] = { "captured.bytes", "Captured bytes " },
+ [CLIENT_CTR_PKTS] = { "captured.pkts", "Captured packets " },
+ [CLIENT_CTR_2BIG] = { "bpf.too_big", "Captured data too big " },
+ [CLIENT_CTR_NOMEM] = { "client.no_mem", "No memory available " },
+ [CLIENT_CTR_QERR] = { "client.queue_err", "Can not queue data " },
+};
+
+static const struct rate_ctr_group_desc pcap_client_ctr_group_desc = {
+ .group_name_prefix = "pcap.client",
+ .group_description = "PCAP Client statistics",
+ .num_ctr = ARRAY_SIZE(pcap_client_ctr_desc),
+ .ctr_desc = pcap_client_ctr_desc,
+ .class_id = OSMO_STATS_CLASS_GLOBAL,
+};
+
static struct vty_app_info vty_info = {
.name = "OsmoPCAPClient",
.version = PACKAGE_VERSION,
@@ -198,6 +216,12 @@ int main(int argc, char **argv)
osmo_wqueue_init(&pcap_client->wqueue, 10);
pcap_client->wqueue.bfd.fd = -1;
+ /* initialize the stats interface */
+ pcap_client->ctrg = rate_ctr_group_alloc(pcap_client, &pcap_client_ctr_group_desc, 0);
+ if (!pcap_client->ctrg) {
+ LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate rate ctr\n");
+ exit(1);
+ }
if (vty_read_config_file(config_file, NULL) < 0) {
LOGP(DCLIENT, LOGL_ERROR,
diff --git a/src/osmo_client_network.c b/src/osmo_client_network.c
index ac9d7cd..7812ff6 100644
--- a/src/osmo_client_network.c
+++ b/src/osmo_client_network.c
@@ -1,7 +1,7 @@
/*
* osmo-pcap-client code
*
- * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2011-2016 by Holger Hans Peter Freyther <holger@moiji-mobile.com>
* (C) 2011 by On-Waves
* All Rights Reserved
*
@@ -25,6 +25,7 @@
#include <osmo-pcap/wireformat.h>
#include <osmocom/core/msgb.h>
+#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/select.h>
#include <osmocom/core/socket.h>
@@ -61,6 +62,7 @@ static void write_data(struct osmo_pcap_client *client, struct msgb *msg)
{
if (osmo_wqueue_enqueue(&client->wqueue, msg) != 0) {
LOGP(DCLIENT, LOGL_ERROR, "Failed to enqueue.\n");
+ rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_QERR]);
msgb_free(msg);
return;
}
@@ -107,12 +109,14 @@ void osmo_client_send_data(struct osmo_pcap_client *client,
if (in_hdr->caplen > 9000) {
LOGP(DCLIENT, LOGL_ERROR,
"Capture len too big %zu\n", in_hdr->caplen);
+ rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_2BIG]);
return;
}
msg = msgb_alloc(9000 + sizeof(*om_hdr) + sizeof(*hdr), "data-data");
if (!msg) {
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate.\n");
+ rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_NOMEM]);
return;
}
@@ -130,6 +134,8 @@ void osmo_client_send_data(struct osmo_pcap_client *client,
memcpy(msg->l3h, data, in_hdr->caplen);
om_hdr->len = htons(msgb_l2len(msg));
+ rate_ctr_add(&client->ctrg->ctr[CLIENT_CTR_BYTES], hdr->caplen);
+ rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_PKTS]);
write_data(client, msg);
}
@@ -191,5 +197,6 @@ void osmo_client_connect(struct osmo_pcap_client *client)
return;
}
+ rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_CONNECT]);
osmo_client_send_link(client);
}