Module: sip-router Branch: master Commit: d0d298070fdbb015a96f209fa3c925ba71e3a37b URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d0d29807...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Mon May 27 13:54:23 2013 +0300
modules/usrloc: added two new rpc commands ul.users and ul.contacts
- for accessing number of different AoRs and contacts in a location table
---
modules/usrloc/README | 22 +++++++ modules/usrloc/doc/usrloc_admin.xml | 31 ++++++++++ modules/usrloc/ul_rpc.c | 111 +++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 0 deletions(-)
diff --git a/modules/usrloc/README b/modules/usrloc/README index 05b8535..02227b0 100644 --- a/modules/usrloc/README +++ b/modules/usrloc/README @@ -87,6 +87,8 @@ Bogdan-Andrei Iancu 6.4. ul.rm_contact table AOR contact 6.5. ul.flush 6.6. ul.add + 6.7. ul.users + 6.8. ul.contacts
7. Statistics
@@ -221,6 +223,8 @@ Chapter 1. Admin Guide 6.4. ul.rm_contact table AOR contact 6.5. ul.flush 6.6. ul.add + 6.7. ul.users + 6.8. ul.contacts
7. Statistics
@@ -836,6 +840,8 @@ modparam("usrloc", "db_ops_ruid", 1) 6.4. ul.rm_contact table AOR contact 6.5. ul.flush 6.6. ul.add + 6.7. ul.users + 6.8. ul.contacts
6.1. ul.dump
@@ -892,6 +898,22 @@ modparam("usrloc", "db_ops_ruid", 1) * cflags - per branch flags of the contact * methods - mask with supported requests of the contact
+6.7. ul.users + + Tell number of different users (AoRs) in a location table. + + Parameters: + * table name - location table where the users are looked for, for + example, location. + +6.8. ul.contacts + + Tell number of contacts in a location table. + + Parameters: + * table name - location table where the contacts are looked for, for + example, location. + 7. Statistics
7.1. users diff --git a/modules/usrloc/doc/usrloc_admin.xml b/modules/usrloc/doc/usrloc_admin.xml index 78be5e8..7745ffe 100644 --- a/modules/usrloc/doc/usrloc_admin.xml +++ b/modules/usrloc/doc/usrloc_admin.xml @@ -1157,6 +1157,37 @@ modparam("usrloc", "db_ops_ruid", 1) </para></listitem> </itemizedlist> </section> + + <section> + <title> + <function moreinfo="none">ul.users</function> + </title> + <para> + Tell number of different users (AoRs) in a location table. + </para> + <para>Parameters: </para> + <itemizedlist> + <listitem><para> + <emphasis>table name</emphasis> - location table where the users are looked for, for example, location. + </para></listitem> + </itemizedlist> + </section> + + <section> + <title> + <function moreinfo="none">ul.contacts</function> + </title> + <para> + Tell number of contacts in a location table. + </para> + <para>Parameters: </para> + <itemizedlist> + <listitem><para> + <emphasis>table name</emphasis> - location table where the contacts are looked for, for example, location. + </para></listitem> + </itemizedlist> + </section> + </section><!-- RPC commands -->
diff --git a/modules/usrloc/ul_rpc.c b/modules/usrloc/ul_rpc.c index 7c10584..e0ebaf4 100644 --- a/modules/usrloc/ul_rpc.c +++ b/modules/usrloc/ul_rpc.c @@ -637,6 +637,115 @@ static const char* ul_rpc_add_doc[2] = { 0 };
+#define QUERY_LEN 256 + +static void ul_rpc_users(rpc_t* rpc, void* ctx) +{ + str table = {0, 0}; + char query[QUERY_LEN]; + str query_str; + db1_res_t* res; + int count; + + if (db_mode == NO_DB) { + rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); + return; + } + + if (rpc->scan(ctx, "S", &table) != 1) { + rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); + return; + } + + if (user_col.len + domain_col.len + table.len + 32 > QUERY_LEN) { + rpc->fault(ctx, 500, "Too long database query"); + return; + } + + if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + rpc->fault(ctx, 500, "Database does not support raw queries"); + return; + } + if (ul_dbf.use_table(ul_dbh, &table) < 0) { + rpc->fault(ctx, 500, "Failed to use table"); + return; + } + + memset(query, 0, QUERY_LEN); + query_str.len = snprintf(query, QUERY_LEN, + "SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s", + user_col.len, user_col.s, + domain_col.len, domain_col.s, + table.len, table.s); + query_str.s = query; + if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { + rpc->fault(ctx, 500, "Failed to query AoR count"); + return; + } + + count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); + ul_dbf.free_result(ul_dbh, res); + + rpc->add(ctx, "d", count); +} + +static const char* ul_rpc_users_doc[2] = { + "Tell number of different users (AoRs) in database table (db_mode!=0 only)", + 0 +}; + +static void ul_rpc_contacts(rpc_t* rpc, void* ctx) +{ + str table = {0, 0}; + char query[QUERY_LEN]; + str query_str; + db1_res_t* res; + int count; + + if (db_mode == NO_DB) { + rpc->fault(ctx, 500, "Command is not supported in db_mode=0"); + return; + } + + if (rpc->scan(ctx, "S", &table) != 1) { + rpc->fault(ctx, 500, "Not enough parameters (table to lookup)"); + return; + } + + if (table.len + 22 > QUERY_LEN) { + rpc->fault(ctx, 500, "Too long database query"); + return; + } + + if (!DB_CAPABILITY(ul_dbf, DB_CAP_RAW_QUERY)) { + rpc->fault(ctx, 500, "Database does not support raw queries"); + return; + } + if (ul_dbf.use_table(ul_dbh, &table) < 0) { + rpc->fault(ctx, 500, "Failed to use table"); + return; + } + + memset(query, 0, QUERY_LEN); + query_str.len = snprintf(query, QUERY_LEN, "SELECT COUNT(*) FROM %.*s", + table.len, table.s); + query_str.s = query; + if (ul_dbf.raw_query(ul_dbh, &query_str, &res) < 0) { + rpc->fault(ctx, 500, "Failed to query contact count"); + return; + } + + count = (int)VAL_INT(ROW_VALUES(RES_ROWS(res))); + ul_dbf.free_result(ul_dbh, res); + + rpc->add(ctx, "d", count); +} + +static const char* ul_rpc_contacts_doc[2] = { + "Tell number of contacts in database table (db_mode=3 only)", + 0 +}; + rpc_export_t ul_rpc[] = { {"ul.dump", ul_rpc_dump, ul_rpc_dump_doc, 0}, {"ul.lookup", ul_rpc_lookup, ul_rpc_lookup_doc, 0}, @@ -644,6 +753,8 @@ rpc_export_t ul_rpc[] = { {"ul.rm_contact", ul_rpc_rm_contact, ul_rpc_rm_contact_doc, 0}, {"ul.flush", ul_rpc_flush, ul_rpc_flush_doc, 0}, {"ul.add", ul_rpc_add, ul_rpc_add_doc, 0}, + {"ul.users", ul_rpc_users, ul_rpc_users_doc, 0}, + {"ul.contacts", ul_rpc_contacts, ul_rpc_contacts_doc, 0}, {0, 0, 0, 0} };
27 maj 2013 kl. 12:55 skrev Juha Heinanen jh@tutpro.com:
- query_str.len = snprintf(query, QUERY_LEN,
"SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s",
user_col.len, user_col.s,
domain_col.len, domain_col.s,
table.len, table.s);
While this work in the short run, we might want to improve the db API to include a request for number of entries in order to support data storage that doesn't support raw SQL statements.
/O
Olle E. Johansson writes:
27 maj 2013 kl. 12:55 skrev Juha Heinanen jh@tutpro.com:
- query_str.len = snprintf(query, QUERY_LEN,
"SELECT COUNT(DISTINCT %.*s, %.*s) FROM %.*s",
user_col.len, user_col.s,
domain_col.len, domain_col.s,
table.len, table.s);
While this work in the short run, we might want to improve the db API to include a request for number of entries in order to support data storage that doesn't support raw SQL statements.
i agree, but i'm not myself expert in db api.
by the way, i didn't get any comment to this db api related question:
http://lists.sip-router.org/pipermail/sr-dev/2013-May/020062.html
-- juha
Hello,
the commands are querying the database and the results can be inaccurate, or at least not something I would expect.
In db_mode=DB_WRITEBACK, there can be expired records that are not yet deleted, they will be at the next timer trigger. Also, DB_READONLY might not reflect properly the correct situation.
Also, cache-only mode is not covered, so it is strictly related to database records. I would suggest the names of the commands should reflect somehow that, to be something like 'dbusers' and 'dbcontacts' or similar.
FYI, there are counters (statistics) for the two values you were looking for, but working only for one location table (or all together): - http://kamailio.org/docs/modules/devel/modules/usrloc.html#idp1873288
Cheers, Daniel
On 5/27/13 12:55 PM, Juha Heinanen wrote:
Module: sip-router Branch: master Commit: d0d298070fdbb015a96f209fa3c925ba71e3a37b URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d0d29807...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Mon May 27 13:54:23 2013 +0300
modules/usrloc: added two new rpc commands ul.users and ul.contacts
- for accessing number of different AoRs and contacts in a location table
Daniel-Constantin Mierla writes:
the commands are querying the database and the results can be inaccurate, or at least not something I would expect.
they just return the described values from database table, nothing more or less is claimed.
In db_mode=DB_WRITEBACK, there can be expired records that are not yet deleted, they will be at the next timer trigger. Also, DB_READONLY might not reflect properly the correct situation.
Also, cache-only mode is not covered, so it is strictly related to database records. I would suggest the names of the commands should reflect somehow that, to be something like 'dbusers' and 'dbcontacts' or similar.
FYI, there are counters (statistics) for the two values you were looking for, but working only for one location table (or all together):
http://kamailio.org/docs/modules/devel/modules/usrloc.html#idp1873288
which ones? i checked the above page and didn't find them.
sure, i can change the names.
-- juha
On 5/27/13 4:52 PM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
the commands are querying the database and the results can be inaccurate, or at least not something I would expect.
they just return the described values from database table, nothing more or less is claimed.
I was referring that one may expect to return the number of valid contacts (not including the expired ones).
In db_mode=DB_WRITEBACK, there can be expired records that are not yet deleted, they will be at the next timer trigger. Also, DB_READONLY might not reflect properly the correct situation. Also, cache-only mode is not covered, so it is strictly related to database records. I would suggest the names of the commands should reflect somehow that, to be something like 'dbusers' and 'dbcontacts' or similar.
FYI, there are counters (statistics) for the two values you were looking for, but working only for one location table (or all together):
http://kamailio.org/docs/modules/devel/modules/usrloc.html#idp1873288
which ones? i checked the above page and didn't find them.
I guess the html readme was regenerated, the id in the page different, the link being now:
http://kamailio.org/docs/modules/devel/modules/usrloc.html#idp1909616
(another good reason to introduce section id in docbook files).
The usrloc statistics for users and contacts return number of distinct aors and contacts managed by the module. You can see them in the output of 'kamctl stats'.
Cheers, Daniel
sure, i can change the names.
-- juha
Daniel-Constantin Mierla writes:
I was referring that one may expect to return the number of valid contacts (not including the expired ones).
ok, i can make that change.
I guess the html readme was regenerated, the id in the page different, the link being now:
http://kamailio.org/docs/modules/devel/modules/usrloc.html#idp1909616
(another good reason to introduce section id in docbook files).
The usrloc statistics for users and contacts return number of distinct aors and contacts managed by the module. You can see them in the output of 'kamctl stats'.
i don't see how those would apply to db_mode=3. readme talks about memory cache:
7.1. users
Number of AOR existing in the USRLOC memory cache for that domain - can not be resetted; this statistic will be register for each used domain (Ex: location).
7.2. contacts
Number of contacts existing in the USRLOC memory cache for that domain - can not be resetted; this statistic will be register for each used domain (Ex: location).
perhaps i'm misunderstanding something?
-- juha
On 5/27/13 6:04 PM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
I was referring that one may expect to return the number of valid contacts (not including the expired ones).
ok, i can make that change.
No need to change if you don't want that. I was just saying from the perspective of what I understood is should return, but would be good for documentation to clarify this aspect of what records are counted.
I guess the html readme was regenerated, the id in the page different, the link being now:
http://kamailio.org/docs/modules/devel/modules/usrloc.html#idp1909616
(another good reason to introduce section id in docbook files).
The usrloc statistics for users and contacts return number of distinct aors and contacts managed by the module. You can see them in the output of 'kamctl stats'.
i don't see how those would apply to db_mode=3. readme talks about memory cache:
I haven't used with db only and indeed seems it is not for db only, the problem could be the deletion of expired contacts that is done in one query, thus not knowing what to decrease.
Cheers, Daniel
7.1. users
Number of AOR existing in the USRLOC memory cache for that domain - can not be resetted; this statistic will be register for each used domain (Ex: location).
7.2. contacts
Number of contacts existing in the USRLOC memory cache for that domain - can not be resetted; this statistic will be register for each used domain (Ex: location).
perhaps i'm misunderstanding something?
-- juha