THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.
The following task is now closed:
FS#163 - enable milliseconds precision for accounting
User who did this - Daniel-Constantin Mierla (miconda)
Reason for closing: Implemented
Additional comments about closing: Implemented in master branch, given when time_mode=2 for acc module.
More information can be found at the following URL:
https://sip-router.org/tracker/index.php?do=details&task_id=163
You are receiving this message because you have requested it from the Flyspray bugtracking system. If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.
Module: sip-router
Branch: master
Commit: 6dc04484e39ceab4887b375d2510f35892d695eb
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6dc0448…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Sep 5 11:54:03 2013 +0200
acc: for time_mode=1, save timestamp in time_attr and microsecs in time_exten
- database records stores time as datetime value
- new parameter time_exten to allow customization of attribute name
---
modules/acc/README | 39 ++++++++++++++++++++++++++++-----------
modules/acc/acc.c | 26 +++++++++++++++++---------
modules/acc/acc_mod.c | 2 ++
modules/acc/acc_mod.h | 1 +
modules/acc/doc/acc_admin.xml | 28 ++++++++++++++++++++++++----
5 files changed, 72 insertions(+), 24 deletions(-)
diff --git a/modules/acc/README b/modules/acc/README
index e837964..d54cd54 100644
--- a/modules/acc/README
+++ b/modules/acc/README
@@ -129,6 +129,7 @@ Sven Knoblich
6.46. cdrs_table (str)
6.47. time_mode (int)
6.48. time_attr (str)
+ 6.49. time_exten (str)
7. Functions
@@ -189,10 +190,11 @@ Sven Knoblich
1.46. cdrs_table example
1.47. time_mode example
1.48. time_attr example
- 1.49. acc_log_request usage
- 1.50. acc_db_request usage
- 1.51. acc_rad_request usage
- 1.52. acc_diam_request usage
+ 1.49. time_exten example
+ 1.50. acc_log_request usage
+ 1.51. acc_db_request usage
+ 1.52. acc_rad_request usage
+ 1.53. acc_diam_request usage
Chapter 1. Admin Guide
@@ -285,6 +287,7 @@ Chapter 1. Admin Guide
6.46. cdrs_table (str)
6.47. time_mode (int)
6.48. time_attr (str)
+ 6.49. time_exten (str)
7. Functions
@@ -695,6 +698,7 @@ $dlg_var(callee) = $avp(callee); #callee='C'
6.46. cdrs_table (str)
6.47. time_mode (int)
6.48. time_attr (str)
+ 6.49. time_exten (str)
6.1. early_media (integer)
@@ -1186,8 +1190,7 @@ modparam("acc", "cdrs_table", "acc_cdrs")
Values can be:
* 0 - (default), save only unix timestamp for syslog and datetime for
database.
- * 1 - save microseconds part (does not include the seconds in the
- value) in time_attr.
+ * 1 - save seconds in time_attr and microseconds in time_exten.
* 3 - save seconds.miliseconds in time_attr.
Example 1.47. time_mode example
@@ -1203,8 +1206,22 @@ modparam("acc", "time_mode", 1)
* 1 - time_attr column has to be int.
* 2 - time_attr column has to be double.
+ For time_mode=1, this attribute is not written in syslog, because time
+ value is already unix timestamp, but in db accounting time value is
+ datetime and requires a function to get the timestamp.
+
Example 1.48. time_attr example
-modparam("acc", "time_attr", "micorsecs")
+modparam("acc", "time_attr", "seconds")
+
+6.49. time_exten (str)
+
+ Name of the syslog attribute or database column where to store extended
+ value related to the time of event.
+
+ It is used now only for time_mode=1 and database column has to be int:
+
+ Example 1.49. time_exten example
+modparam("acc", "time_exten", "micorsecs")
7. Functions
@@ -1225,7 +1242,7 @@ modparam("acc", "time_attr", "micorsecs")
This function can be used from ANY_ROUTE.
- Example 1.49. acc_log_request usage
+ Example 1.50. acc_log_request usage
...
acc_log_request("Some comment");
...
@@ -1243,7 +1260,7 @@ acc_log_request("Some comment");
This function can be used from ANY_ROUTE.
- Example 1.50. acc_db_request usage
+ Example 1.51. acc_db_request usage
...
acc_db_request("Some comment", "SomeTable");
acc_db_request("Some comment", "acc_$time(year)_$time(mon)");
@@ -1259,7 +1276,7 @@ acc_db_request("Some comment", "acc_$time(year)_$time(mon)");
This function can be used from ANY_ROUTE.
- Example 1.51. acc_rad_request usage
+ Example 1.52. acc_rad_request usage
...
acc_rad_request("Some comment");
...
@@ -1274,7 +1291,7 @@ acc_rad_request("Some comment");
This function can be used from ANY_ROUTE.
- Example 1.52. acc_diam_request usage
+ Example 1.53. acc_diam_request usage
...
acc_diam_request("Some comment");
...
diff --git a/modules/acc/acc.c b/modules/acc/acc.c
index 2849809..8a6f3cc 100644
--- a/modules/acc/acc.c
+++ b/modules/acc/acc.c
@@ -93,10 +93,11 @@ extern struct acc_extra *db_extra;
#endif
/* arrays used to collect the values before being
- * pushed to the storage backend (whatever used) */
-static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+2];
-static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+2];
-static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+2];
+ * pushed to the storage backend (whatever used)
+ * (3 = datetime + max 2 from time_mode) */
+static str val_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
+static int int_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
+static char type_arr[ACC_CORE_LEN+MAX_ACC_EXTRA+MAX_ACC_LEG+3];
/********************************************
* acc CORE function
@@ -279,7 +280,7 @@ int acc_log_request( struct sip_msg *rq)
if(acc_time_mode==1) {
LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%u%s",
acc_env.text.len, acc_env.text.s,(unsigned long) acc_env.ts,
- acc_time_attr.s, (unsigned int)acc_env.tv.tv_usec,
+ acc_time_exten.s, (unsigned int)acc_env.tv.tv_usec,
log_msg);
} else if(acc_time_mode==2) {
LM_GEN2(log_facility, log_level, "%.*stimestamp=%lu;%s=%.3f%s",
@@ -304,9 +305,10 @@ int acc_log_request( struct sip_msg *rq)
#ifdef SQL_ACC
-/* caution: keys need to be aligned to core format */
-static db_key_t db_keys[ACC_CORE_LEN+2+MAX_ACC_EXTRA+MAX_ACC_LEG];
-static db_val_t db_vals[ACC_CORE_LEN+2+MAX_ACC_EXTRA+MAX_ACC_LEG];
+/* caution: keys need to be aligned to core format
+ * (3 = datetime + max 2 from time_mode) */
+static db_key_t db_keys[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
+static db_val_t db_vals[ACC_CORE_LEN+3+MAX_ACC_EXTRA+MAX_ACC_LEG];
int acc_get_db_handlers(void **vf, void **vh) {
@@ -336,7 +338,10 @@ static void acc_db_init_keys(void)
db_keys[n++] = &acc_time_col;
time_idx = n-1;
if(acc_time_mode==1 || acc_time_mode==2) {
- db_keys[n++] = &acc_time_attr;;
+ db_keys[n++] = &acc_time_attr;
+ if(acc_time_mode==1) {
+ db_keys[n++] = &acc_time_exten;
+ }
}
/* init the extra db keys */
@@ -355,6 +360,7 @@ static void acc_db_init_keys(void)
VAL_TYPE(db_vals+time_idx)=DB1_DATETIME;
if(acc_time_mode==1) {
VAL_TYPE(db_vals+time_idx+1)=DB1_INT;
+ VAL_TYPE(db_vals+time_idx+2)=DB1_INT;
} else if(acc_time_mode==2) {
VAL_TYPE(db_vals+time_idx+1)=DB1_DOUBLE;
}
@@ -418,6 +424,8 @@ int acc_db_request( struct sip_msg *rq)
VAL_TIME(db_vals+(m++)) = acc_env.ts;
/* extra time value */
if(acc_time_mode==1) {
+ VAL_INT(db_vals+(m++)) = (int)acc_env.tv.tv_sec;
+ i++;
VAL_INT(db_vals+(m++)) = (int)acc_env.tv.tv_usec;
i++;
} else if(acc_time_mode==2) {
diff --git a/modules/acc/acc_mod.c b/modules/acc/acc_mod.c
index 1f7540b..a36ecbe 100644
--- a/modules/acc/acc_mod.c
+++ b/modules/acc/acc_mod.c
@@ -116,6 +116,7 @@ int acc_prepare_flag = -1; /*!< should the request be prepared for later acc */
int acc_time_mode = 0;
str acc_time_attr = str_init("time_attr");
+str acc_time_exten = str_init("time_exten");
/*@}*/
@@ -306,6 +307,7 @@ static param_export_t params[] = {
/* time-mode-specific */
{"time_mode", INT_PARAM, &acc_time_mode },
{"time_attr", PARAM_STR, &acc_time_attr },
+ {"time_exten", PARAM_STR, &acc_time_exten },
{"cdrs_table", PARAM_STR, &acc_cdrs_table },
{0,0,0}
};
diff --git a/modules/acc/acc_mod.h b/modules/acc/acc_mod.h
index b291abd..98cef33 100644
--- a/modules/acc/acc_mod.h
+++ b/modules/acc/acc_mod.h
@@ -99,6 +99,7 @@ extern int acc_db_insert_mode;
/* time mode */
extern int acc_time_mode;
extern str acc_time_attr;
+extern str acc_time_exten;
#endif
diff --git a/modules/acc/doc/acc_admin.xml b/modules/acc/doc/acc_admin.xml
index 78f025a..6ebb9a9 100644
--- a/modules/acc/doc/acc_admin.xml
+++ b/modules/acc/doc/acc_admin.xml
@@ -1278,8 +1278,8 @@ modparam("acc", "cdrs_table", "acc_cdrs")
timestamp for syslog and datetime for database.</para>
</listitem>
<listitem>
- <para><emphasis>1</emphasis> - save microseconds part (does not
- include the seconds in the value) in time_attr.</para>
+ <para><emphasis>1</emphasis> - save seconds in time_attr and
+ microseconds in time_exten.</para>
</listitem>
<listitem>
<para><emphasis>3</emphasis> - save seconds.miliseconds
@@ -1312,11 +1312,31 @@ modparam("acc", "time_mode", 1)
<para><emphasis>2</emphasis> - time_attr column has to be double.</para>
</listitem>
</itemizedlist>
-
+ <para>
+ For time_mode=1, this attribute is not written in syslog, because time
+ value is already unix timestamp, but in db accounting time value is
+ datetime and requires a function to get the timestamp.
+ </para>
<example>
<title>time_attr example</title>
<programlisting format="linespecific">
-modparam("acc", "time_attr", "micorsecs")
+modparam("acc", "time_attr", "seconds")
+</programlisting>
+ </example>
+ </section>
+ <section id="acc.p.time_exten">
+ <title><varname>time_exten</varname> (str)</title>
+ <para>
+ Name of the syslog attribute or database column where to store extended
+ value related to the time of event.
+ </para>
+ <para>
+ It is used now only for time_mode=1 and database column has to be int:
+ </para>
+ <example>
+ <title>time_exten example</title>
+ <programlisting format="linespecific">
+modparam("acc", "time_exten", "micorsecs")
</programlisting>
</example>
</section>
Hello,
being requested several times and as I did get to do some acc work, I
added the code for storing dialog-based cdrs to database. But I had no
time to setup a testbed for it, hopefully those interested in the
feature will help testing a bit.
It follows closely the same logic as writing cdrs to syslog. You have to
create table acc_cdrs (see utils/kamctl/mysql/acc-create.sql), then add
extra columns as you need. The attribute name in cdr_extra has to match
the column name (the type for extra columns have to be string/varchar).
In kamailio.cfg you have to set the cdrs_table parameter to acc_cdrs.
One odd by now is that duration column is also string, because is how
existing code (for syslog writing) stored in internally -- plan to
change it in the near future, for now sql gives the tools for converting.
More details can be found in acc module readme:
- http://kamailio.org/docs/modules/devel/modules/acc.html
Let me know the results, to tune it properly.
Cheers,
Daniel
--
Daniel-Constantin Mierla - http://www.asipto.comhttp://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio Advanced Trainings - Berlin, Oct 21-24; Miami, Nov 11-13, 2013
- more details about Kamailio trainings at http://www.asipto.com -