aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/db.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@netfilter.org>2009-12-22 19:07:32 +0100
committerHarald Welte <laforge@netfilter.org>2009-12-22 20:42:40 +0100
commitffa55a4e8783419f60932ef2f9e872293cf932b9 (patch)
treec615771fe04a89807a012d8e100de53847b70d0f /openbsc/src/db.c
parent4983921af1a84ea20c6be7944bf0ff4928578a69 (diff)
statistics: Introduce 'struct counter' instead of using unsigned long
This has the advantage that counters can be added all over the code very easily, while having only one routine that stores all of the current counter values to the database. The counters are synced every 60 seconds, providing relatively fine grained statistics about the network usage as time passes by.
Diffstat (limited to 'openbsc/src/db.c')
-rw-r--r--openbsc/src/db.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 707d877bb..916527de6 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -25,6 +25,7 @@
#include <openbsc/db.h>
#include <openbsc/talloc.h>
#include <openbsc/debug.h>
+#include <openbsc/statistics.h>
#include <libgen.h>
#include <stdio.h>
@@ -117,6 +118,12 @@ static char *create_stmts[] = {
"subscriber_id INTEGER NOT NULL, "
"apdu BLOB "
")",
+ "CREATE TABLE IF NOT EXISTS Counters ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "timestamp TIMESTAMP NOT NULL, "
+ "value INTEGER NOT NULL "
+ "name TEXT NOT NULL, "
+ ")",
};
void db_error_func(dbi_conn conn, void* data) {
@@ -902,3 +909,24 @@ int db_apdu_blob_store(struct gsm_subscriber *subscr,
dbi_result_free(result);
return 0;
}
+
+int db_store_counter(struct counter *ctr)
+{
+ dbi_result result;
+ char *q_name;
+
+ dbi_conn_quote_string_copy(conn, ctr->name, &q_name);
+
+ result = dbi_conn_queryf(conn,
+ "INSERT INTO Counters "
+ "(timestamp,name,value) VALUES "
+ "(datetime('now'),%s,%lu)", q_name, ctr->value);
+
+ free(q_name);
+
+ if (!result)
+ return -EIO;
+
+ dbi_result_free(result);
+ return 0;
+}