[ZBX-5717] icmppingloss result percent is not really possible Created: 2012 Oct 22 Updated: 2017 May 30 Resolved: 2015 Apr 09 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Agent (G), Proxy (P), Server (S) |
Affects Version/s: | 2.0.3 |
Fix Version/s: | 2.0.15rc1, 2.2.10rc1, 2.4.5rc1, 2.5.0 |
Type: | Incident report | Priority: | Minor |
Reporter: | sles | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | icmpping, rounding | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
Centos 6/x86-64 |
Description |
We have an element icmppingloss[,20,,,] and on of latest values is: 2012.???.22 11:36:18 9 which means that 9% of packets is lost, i.e. 1.8 packets is lost, which is not possible Looks like bug |
Comments |
Comment by richlv [ 2012 Oct 22 ] |
what's the type of information for that item ? |
Comment by sles [ 2012 Oct 22 ] |
Числовой (целое положительное) I guess |
Comment by richlv [ 2012 Oct 22 ] |
then please set it to float (or whatever is it in the translated version ) |
Comment by sles [ 2012 Oct 22 ] |
why? is 10.0 = 9 ? |
Comment by richlv [ 2012 Oct 22 ] |
hmm, good point. 9 probably shouldn't be there, although float might give better idea about what's happening. also, which fping version ? usually zabbix should just use result from fping anyway |
Comment by sles [ 2012 Oct 23 ] |
Hello! I'll change data type to float and when loss will be here again I'll report about results. btw, fping -v it is from Thank you! |
Comment by sles [ 2012 Oct 30 ] |
Well, I can't reproduce this with float, so something is wrong with data types... |
Comment by Aleksandrs Saveljevs [ 2015 Mar 18 ] |
The problem is that not all numbers are precisely representable in floating-point. In this case, we calculate ping loss percentage as follows: value_dbl = 100 * (1 - (double)hosts[h].rcv / (double)hosts[h].cnt); If rcv=18 and cnt=20, then 18/20 cannot be represented precisely and so value_dbl becomes approximately 9.99999999999999822364, which upon conversion to integer gets truncated to 9. If we rewrite the calculation to use less floating-point operations, then it works well:
value_dbl = 100 * ((hosts[h].cnt - hosts[h].rcv) / (double)hosts[h].cnt);
For the future, we should make it a guideline to write expressions with as few floating-point operations as possible. |
Comment by Aleksandrs Saveljevs [ 2015 Mar 18 ] |
Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-5717 . |
Comment by Alexander Vladishev [ 2015 Mar 30 ] |
(1) Take a look at my changes in r52930. asaveljevs Looks good. CLOSED. |
Comment by Aleksandrs Saveljevs [ 2015 Mar 30 ] |
(2) Please take a look at changes in r52935. It changes how the expression is written: - value_dbl = 100 * ((host->cnt - host->rcv) / (double)host->cnt); + value_dbl = (100 * (host->cnt - host->rcv)) / (double)host->cnt; A number like 0.1 cannot be represented in floating-point exactly. With "rcv=9" and "cnt=10", the parentheses in the first expression will have 0.1 as an intermediate result. In the second expression, evaluation will proceed as (100 * (10 - 9)) / 10.0 = (100 * 1) / 10.0 = 100 / 10.0 = 10.0, all of which can be represented in floating-point exactly. sasha Looks good! CLOSED |
Comment by Aleksandrs Saveljevs [ 2015 Mar 30 ] |
(3) Documented the guideline at https://www.zabbix.org/wiki/C_coding_guidelines#Best_practices. sasha CLOSED |
Comment by Aleksandrs Saveljevs [ 2015 Apr 09 ] |
Fixed in pre-2.0.15 r53022, pre-2.2.10 r53023, pre-2.4.5 r53024, pre-2.5.0 (trunk) r53025. |