aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/db.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-05-13 11:45:07 +0200
committerHarald Welte <laforge@gnumonks.org>2010-05-13 11:45:07 +0200
commitf2b4cd7b866286b905271283f3646a325417760a (patch)
tree4ff1287a99734d57a63fb64f524fa168ab2d2ee2 /openbsc/src/db.c
parent0ab535bfc391a6f53b13a565bfe9464e77045165 (diff)
[GPRS] NS: Start to use rate_ctr_group code from libosmocore
Every NS-VC now has a set of counters for incoming and outgoing number of packets and bytes. We also split the VTY part of the gprs_ns.c implementation into gprs_ns_vty.c to make sure the protocol can actually be used without the VTY code being present.
Diffstat (limited to 'openbsc/src/db.c')
-rw-r--r--openbsc/src/db.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 8bf47ab38..f7fb3b457 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -20,13 +20,8 @@
*
*/
-#include <openbsc/gsm_data.h>
-#include <openbsc/gsm_04_11.h>
-#include <openbsc/db.h>
-#include <osmocore/talloc.h>
-#include <openbsc/debug.h>
-#include <osmocore/statistics.h>
-
+#include <stdint.h>
+#include <inttypes.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
@@ -34,6 +29,14 @@
#include <errno.h>
#include <dbi/dbi.h>
+#include <openbsc/gsm_data.h>
+#include <openbsc/gsm_04_11.h>
+#include <openbsc/db.h>
+#include <osmocore/talloc.h>
+#include <openbsc/debug.h>
+#include <osmocore/statistics.h>
+#include <osmocore/rate_ctr.h>
+
static char *db_basename = NULL;
static char *db_dirname = NULL;
static dbi_conn conn;
@@ -1180,3 +1183,42 @@ int db_store_counter(struct counter *ctr)
dbi_result_free(result);
return 0;
}
+
+static int db_store_rate_ctr(struct rate_ctr_group *ctrg, unsigned int num,
+ char *q_prefix)
+{
+ dbi_result result;
+ char *q_name;
+
+ dbi_conn_quote_string_copy(conn, ctrg->desc->ctr_desc[num].name,
+ &q_name);
+
+ result = dbi_conn_queryf(conn,
+ "Insert INTO Counters "
+ "(timestamp,name,value) VALUES "
+ "(datetime('now'),%s.%s,%"PRIu64")",
+ q_prefix, q_name, ctrg->ctr[num].current);
+
+ free(q_name);
+
+ if (!result)
+ return -EIO;
+
+ dbi_result_free(result);
+ return 0;
+}
+
+int db_store_rate_ctr_group(struct rate_ctr_group *ctrg)
+{
+ unsigned int i;
+ char *q_prefix;
+
+ dbi_conn_quote_string_copy(conn, ctrg->name_prefix, &q_prefix);
+
+ for (i = 0; i < ctrg->desc->num_ctr; i++)
+ db_store_rate_ctr(ctrg, i, q_prefix);
+
+ free(q_prefix);
+
+ return 0;
+}