[Home]

Summary:ASTERISK-15409: [patch] Duration and Billsec Decimal Place
Reporter:Cian (cianmaher)Labels:
Date Opened:2010-01-06 14:22:26.000-0600Date Closed:2010-06-08 18:48:19
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Addons/cdr_mysql
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) cdrhires.diff
( 1) hrbillsec_v2.diff
( 2) hrtime_mysql_1.6.2.diff
Description:My problem at present is I has Sangoma ss7 box, woomera, asterisk1.6.2 and addons 1.6.2 on a server that is connected to 8 ss7 trunks with other carriers. I have asterisk writing cdr's to mysql however it appears to round up always.

For example:

One of the Carriers reports a call duration of 31.7seconds but we report it as 33seconds assuming because there is some transit duration of approx 0.4 - 0.5 of a second which brings me to 32.1 or 32.2 but then it is rounded up to 33.

My questions are:

* Is it possible for asterisk not to round the duration and billsec?
* Is it possible to show duration and billsec with a decimal to show the true figure?

Thanks in advance
Comments:By: Leif Madsen (lmadsen) 2010-01-06 15:23:10.000-0600

This feels like a feature request to me. I presume the issue is that the values involved here are setup as 'int' and not 'float'

By: Cian (cianmaher) 2010-01-06 15:33:49.000-0600

So if this is a feature request, does that mean this is not possible at present?

Basically I need to get the exact duration, not a rounded up or rounded down number. I read here that this was something that was available in 1.6 but can not locate and docs that explain how to configure?

https://issues.asterisk.org/view.php?id=13366

By: snuffy (snuffy) 2010-01-08 00:41:58.000-0600

That is correct,

We only take the 'seconds' part of the elapsed time.
The billsec field is only a 'int' so could never be x.y seconds

Someone would have to code a new field into the cdr, probably called 'billmilsec' or 'billusec' and then the extra granularity you want would be available (after req changes to the cdr_xxx backend consumers).

By: Cian (cianmaher) 2010-01-08 04:16:51.000-0600

OK thanks for clearing that up for me. Please could you then add this as a feature request. May be useful in asterisk in the future.

Thanks Again,

Cian

By: Alec Davis (alecdavis) 2010-01-08 04:30:00.000-0600

We're seeing the same 2 second issue with 1.6.1 branch.
Our carrier on our E1 ISDN lines reports 2 seconds less than Asterisk reports for duration. However our carrier only reports in full seconds.

Since 1.6.2, in cdr.conf check that in the "general" section that "initiatedseconds=no", otherwise the billsec may have 1 second added to it. See line below, from cdr.c
  cdr->billsec += cdr->end.tv_usec > cdr->answer.tv_usec ? 1 : 0

We're on 1.6.1, 'initiatedseconds' isn't supported.

By: snuffy (snuffy) 2010-01-11 06:17:10.000-0600

I have coded up a '30min job' to allow for cdrs to be logged with 'hrbilltime' or time billed to the millisecond. (Will put it up in next 24hr)

If you are currently using cdr_pgsql as your backend and the 'billsec' field is 'float' type you may..may get what you want without any patch. (from reading the code in the module)

By: Leif Madsen (lmadsen) 2010-01-11 13:55:41.000-0600

Just to note that feature requests are not handled on the bug tracker, and that patches for new features would only go into trunk, and not existing branches.

By: snuffy (snuffy) 2010-01-11 16:03:46.000-0600

This diff only applies to trunk as it is the only place new features like this can be added

By: Leif Madsen (lmadsen) 2010-01-11 16:56:28.000-0600

Marking this as Confirmed for now as there is a patch attached. I can move this forward to "Ready for Testing" if snuffy can confirm that it is more than just a hack (i.e. it is a patch that could be considered for committing, perhaps with some work after a review).

By: Tilghman Lesher (tilghman) 2010-01-11 17:29:19.000-0600

I disagree with your analysis, snuffy.  The adaptive drivers are already capable of handling multiple decimal places within both duration and billsec, though the timestamps themselves cannot.  This is available in all versions from 1.6.0 forward.

However, it appears that the cdr_mysql driver does not handle duration and billsec this way, although the cdr_pgsql driver does.  Given that it exists in the cdr_pgsql driver, it can be easily added to the other adaptive CDR drivers, as well.

By: snuffy (snuffy) 2010-01-11 18:04:15.000-0600

As discussed on #asterisk-dev

Best way forward is to modify the backends rather than the hack method.
billsec interpretations from cdr_pgsql added to cdr_mysql/cdr_adaptive_odbc etc.

By: snuffy (snuffy) 2010-01-13 18:02:25.000-0600

New patch uploaded, following the better method.
Note for some cdr drivers I had to include a 'hrbillsec' flag in the config (cdr_tds) the rest I could detect, and csv_custom/syslog_custom can just change their config line to '${CDR(billsec,f)}

By: Tilghman Lesher (tilghman) 2010-01-13 19:40:17.000-0600

1) Don't forget duration in func_cdr.c.  You only have billsec in there presently.  In fact, you seem to have neglected "duration" everywhere but in the documentation.
2) For cdr_mysql, the type can also be "decimal".
3) I would eschew the change of cdr_odbc.  This change is more appropriate for cdr_adaptive_odbc, which will eventually replace cdr_odbc.
4) If you insisted on cdr_odbc, note that you cannot use SQL_C_SLONG with a float type.
5) cdr_tds does not appear to have any change at all, other than the addition of a comment.  Oversight?
6) Ditto 5 for cdr_sqlite3_custom.

Once you've made these changes, I'd like to see this patch go up on reviewboard, where we can get more critical comments for improving the code.

By: snuffy (snuffy) 2010-01-14 05:57:47.000-0600

Ok changes have been made.

Latest patch can be found on the reviewboard as review 461.
This includes patches for (mysql/tds/adaptive odbc/odbc/sqllite/sqllite3/csv custom)



By: Leif Madsen (lmadsen) 2010-01-14 06:42:24.000-0600

Marking this as Ready for Review as there is now a link to reviewboard. Thanks for the work on this snuffy!

By: Cian (cianmaher) 2010-02-08 02:25:15.000-0600

Guys,

Using 1.6.2.0 second patch will not work as there is no cdr_mysql.c or func_cdr.c can this patch be made 1.6.2.0 friendly?

Thanks

By: snuffy (snuffy) 2010-02-08 06:13:47.000-0600

cianmaher: I have posted to this issue a diff for 'ast-addons'
This should work fine for you. Post your testing results to the reviewboard link below:

https://reviewboard.asterisk.org/r/461

By: Cian (cianmaher) 2010-02-09 10:57:29.000-0600

Ok guys I have dome some testing directly with our carrier and have found that every call is around 0.5 seconds out.

Example:

Asterisk Duration:  22.5197
Sangoma mpt2 Trace Duration: 22.00970
Carrier Duration: 21.9

While this duration does not seem significant in the general pbx world but its a different story when interconnecting with a carrier.

Both the carrier and the Sangoma traces durations are taken from ANM and RLC in the mtp2 messages. The carrier is using a Nortel DMS and the sangoma durations are pretty close.

I am not proficient in C to try an understand what asterisk is doing that is causing this difference in durations. I would like to understand when asterisk considers a call started and finished as this is probably where my problem resides.

Thanks all for your help so far.

Also to note despite asterisk answering the call immediately the duration and billsec fields differ usually by 0.14ish of a second. Some examples are:

call   duration    billsec
1   |  35.5124 | 35.3704
2   |  44.5764 | 44.4354
3   |  127.304 | 127.161

By: snuffy (snuffy) 2010-02-09 16:24:23.000-0600

cianmaher: What is your distro and what HZ is your kernel running at ?
Also just out of interest was timing source within asterisk are you using.



By: Digium Subversion (svnbot) 2010-06-08 18:48:17

Repository: asterisk
Revision: 269153

U   trunk/CHANGES
U   trunk/UPGRADE.txt
U   trunk/addons/cdr_mysql.c
U   trunk/cdr/cdr_adaptive_odbc.c
U   trunk/cdr/cdr_odbc.c
U   trunk/cdr/cdr_pgsql.c
U   trunk/cdr/cdr_sqlite.c
U   trunk/cdr/cdr_tds.c
U   trunk/configs/cdr_custom.conf.sample
U   trunk/configs/cdr_odbc.conf.sample
U   trunk/configs/cdr_sqlite3_custom.conf.sample
U   trunk/configs/cdr_syslog.conf.sample
U   trunk/configs/cdr_tds.conf.sample
U   trunk/funcs/func_cdr.c

------------------------------------------------------------------------
r269153 | snuffy | 2010-06-08 18:48:17 -0500 (Tue, 08 Jun 2010) | 11 lines

Add High Resolution Times to CDRs for Asterisk

People expressed an interest in having access to the exact length of calls to a finer degree than seconds. See the CHANGES and UPGRADE.txt for usage also updated the sample configs to note the change.

Patch by snuffy.

(closes issue ASTERISK-15409)
Reported by: cianmaher
Tested by: cianmaher, snuffy

Review: https://reviewboard.asterisk.org/r/461/
------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=269153