# Showback incorrect calculation

**URL:** <https://forum.opennebula.io/t/showback-incorrect-calculation/5413>\
**Category:** Product Support\
**Created:** [December 12, 2017, 5:26pm UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413 "2017-12-12T17:26:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brady\_Deetz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/brady_deetz/32/5506_2.png) [@Brady\_Deetz](https://forum.opennebula.io/u/Brady_Deetz)\
**Post date:** [December 12, 2017, 5:26pm UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413/1 "2017-12-12T17:26:11Z")

</div>

I am receiving incorrect calculations with showback.

For example, I have a template with the following settings:  
.000001/mb ram/hr  
.005/cpu/hr  
.0000137/gb disk/hr

That template has:  
3072MB of RAM  
2 vCPU @ 2pCPU  
1x 10GB disk

It ran for 721 hours and opennebula calculated cost to be $414.02. It should be about $9.38

* * *

[root@dc1srvopennebula01 ~]# rpm -qa | grep nebula  
opennebula-flow-5.4.1-1.x86\_64  
opennebula-ruby-5.4.1-1.x86\_64  
opennebula-gate-5.4.1-1.x86\_64  
opennebula-sunstone-5.4.1-1.x86\_64  
opennebula-node-kvm-5.4.1-1.x86\_64  
opennebula-common-5.4.1-1.x86\_64  
opennebula-5.4.1-1.x86\_64  
opennebula-server-5.4.1-1.x86\_64

[root@dc1srvopennebula01 ~]# uname -a  
Linux [dc1srvopennebula01.laureateinstitute.org](http://dc1srvopennebula01.laureateinstitute.org) 3.10.0-693.5.2.el7.x86\_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86\_64 x86\_64 x86\_64 GNU/Linux

[root@dc1srvopennebula01 ~]# cat /etc/centos-release  
CentOS Linux release 7.4.1708 (Core)

AUTOMATIC\_DS\_REQUIREMENTS = "“CLUSTERS/ID” @\> 0"  
AUTOMATIC\_REQUIREMENTS = "(CLUSTER\_ID = 0) & !(PUBLIC\_CLOUD = YES)"  
CLONING\_TEMPLATE\_ID = "47"  
CONTEXT = [  
CONTEXT = “true”,  
DISK\_ID = “1”,  
ETH0\_CONTEXT\_FORCE\_IPV4 = “”,  
ETH0\_DNS = “8.8.8.8”,  
ETH0\_GATEWAY = “10.124.250.1”,  
ETH0\_GATEWAY6 = “”,  
ETH0\_IP = “10.124.250.32”,  
ETH0\_IP6 = “”,  
ETH0\_IP6\_PREFIX\_LENGTH = “”,  
ETH0\_IP6\_ULA = “”,  
ETH0\_MAC = “02:00:0a:7c:fa:20”,  
ETH0\_MASK = “”,  
ETH0\_MTU = “”,  
ETH0\_NETWORK = “”,  
ETH0\_SEARCH\_DOMAIN = “”,  
ETH0\_VLAN\_ID = “2500”,  
ETH0\_VROUTER\_IP = “”,  
ETH0\_VROUTER\_IP6 = “”,  
ETH0\_VROUTER\_MANAGEMENT = “”,  
ETH1\_CONTEXT\_FORCE\_IPV4 = “”,  
ETH1\_DNS = “”,  
ETH1\_GATEWAY = “”,  
ETH1\_GATEWAY6 = “”,  
ETH1\_IP = “10.124.17.120”,  
ETH1\_IP6 = “”,  
ETH1\_IP6\_PREFIX\_LENGTH = “”,  
ETH1\_IP6\_ULA = “”,  
ETH1\_MAC = “02:00:0a:7c:11:78”,  
ETH1\_MASK = “”,  
ETH1\_MTU = “”,  
ETH1\_NETWORK = “”,  
ETH1\_SEARCH\_DOMAIN = “”,  
ETH1\_VLAN\_ID = “17”,  
ETH1\_VROUTER\_IP = “”,  
ETH1\_VROUTER\_IP6 = “”,  
ETH1\_VROUTER\_MANAGEMENT = “”,  
IMAGE = “Context”,  
NETWORK = “YES”,  
SET\_HOSTNAME = “admin”,  
SSH\_PUBLIC\_KEY = “$USER[SSH\_PUBLIC\_KEY]”,  
START\_SCRIPT\_BASE64 = “eXVtIGluc3RhbGwgLXkgaHRvcCB2aW0=”,  
TARGET = “hda” ]  
CPU = "2"  
CPU\_COST = "0.005"  
DISK = [  
ALLOW\_ORPHANS = “YES”,  
CEPH\_HOST = “10.124.103.60 10.124.103.61 10.124.103.62”,  
CEPH\_SECRET = “cee873d6-f586-4732-beb6-ae624ad34864”,  
CEPH\_USER = “libvirt”,  
CLONE = “NO”,  
CLONE\_TARGET = “SELF”,  
CLUSTER\_ID = “0”,  
DATASTORE = “ceph\_one\_image”,  
DATASTORE\_ID = “107”,  
DEV\_PREFIX = “vd”,  
DISK\_ID = “0”,  
DISK\_SNAPSHOT\_TOTAL\_SIZE = “0”,  
DISK\_TYPE = “RBD”,  
DRIVER = “raw”,  
IMAGE = “admin-disk-0”,  
IMAGE\_ID = “282”,  
IMAGE\_STATE = “10”,  
LN\_TARGET = “NONE”,  
ORDER = “1”,  
ORIGINAL\_SIZE = “40960”,  
PERSISTENT = “YES”,  
POOL\_NAME = “one”,  
READONLY = “NO”,  
SAVE = “YES”,  
SIZE = “40960”,  
SOURCE = “one/one-282”,  
TARGET = “vda”,  
TM\_MAD = “ceph”,  
TYPE = “RBD” ]  
DISK\_COST = "1.37e-05"  
FEATURES = [  
ACPI = “yes”,  
GUEST\_AGENT = “yes” ]  
GRAPHICS = [  
LISTEN = “0.0.0.0”,  
PORT = “6031”,  
TYPE = “VNC” ]  
MEMORY = "3072"  
MEMORY\_COST = "1e-06"  
NIC = [  
AR\_ID = “0”,  
BRIDGE = “br0”,  
CLUSTER\_ID = “0”,  
DNS = “8.8.8.8”,  
FILTER\_IP\_SPOOFING = “YES”,  
FILTER\_MAC\_SPOOFING = “YES”,  
GATEWAY = “10.124.250.1”,  
IP = “10.124.250.32”,  
MAC = “02:00:0a:7c:fa:20”,  
NETWORK = “dev-ceph\_public”,  
NETWORK\_ID = “2”,  
NIC\_ID = “0”,  
SECURITY\_GROUPS = “0”,  
TARGET = “one-131-0”,  
VLAN\_ID = “2500”,  
VN\_MAD = “ovswitch” ]  
NIC = [  
AR\_ID = “0”,  
BRIDGE = “br0”,  
CLUSTER\_ID = “0”,  
FILTER\_MAC\_SPOOFING = “YES”,  
IP = “10.124.17.120”,  
MAC = “02:00:0a:7c:11:78”,  
NETWORK = “Prod-IT-Desktop”,  
NETWORK\_ID = “4”,  
NETWORK\_UNAME = “oneadmin”,  
NIC\_ID = “1”,  
SECURITY\_GROUPS = “0”,  
TARGET = “one-131-1”,  
VLAN\_ID = “17”,  
VN\_MAD = “ovswitch” ]  
OS = [  
BOOT = “disk0” ]  
SECURITY\_GROUP\_RULE = [  
PROTOCOL = “ALL”,  
RULE\_TYPE = “OUTBOUND”,  
SECURITY\_GROUP\_ID = “0”,  
SECURITY\_GROUP\_NAME = “default” ]  
SECURITY\_GROUP\_RULE = [  
PROTOCOL = “ALL”,  
RULE\_TYPE = “INBOUND”,  
SECURITY\_GROUP\_ID = “0”,  
SECURITY\_GROUP\_NAME = “default” ]  
TEMPLATE\_ID = "109"  
VCPU = "2"  
VMID = “131”

**Steps to reproduce:**  
create template with costs assigned above

**Current results:**  
414.02

**Expected results:**  
9.38

---

<div class="post-metadata">

**Author:** ![tinova](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/tinova/32/25_2.png) [@tinova](https://forum.opennebula.io/u/tinova)\
**Post date:** [December 12, 2017, 5:49pm UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413/2 "2017-12-12T17:49:37Z")

</div>

This should be fixed in the latest hotfix, 5.4.5. Please build it from source and try again.

---

<div class="post-metadata">

**Author:** ![Brady\_Deetz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/brady_deetz/32/5506_2.png) [@Brady\_Deetz](https://forum.opennebula.io/u/Brady_Deetz)\
**Post date:** [December 13, 2017, 4:19am UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413/3 "2017-12-13T04:19:06Z")

</div>

I upgraded to 5.4.5 using the following github release. [https://github.com/OpenNebula/one/releases/tag/release-5.4.5](https://github.com/OpenNebula/one/releases/tag/release-5.4.5)

The issue is not resolved.

Using the same template defined above, I had a VM run for 0.29 hours with a cost of .17. Extrapolated, that’s the same bad calculation as before.

That said, I don’t see any code in the cherry picked patches for that release that look like they relate to the showback backend [https://github.com/OpenNebula/one/commit/c2c93dab7e2d9deca57f68a21828376266396283](https://github.com/OpenNebula/one/commit/c2c93dab7e2d9deca57f68a21828376266396283)

Am I applying the wrong upgrade?

---

<div class="post-metadata">

**Author:** ![Brady\_Deetz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/brady_deetz/32/5506_2.png) [@Brady\_Deetz](https://forum.opennebula.io/u/Brady_Deetz)\
**Post date:** [December 13, 2017, 5:20am UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413/4 "2017-12-13T05:20:32Z")

</div>

After looking at the db, it looks like disk cost is way higher than expected. This is perhaps my fault.

`select * from vm_showback where month=11 limit 10;`

`| 131 | 2017 | 11 | <SHOWBACK><VMID>131</VMID><VMNAME>admin</VMNAME><UID>0</UID><GID>0</GID><UNAME>oneadmin</UNAME><GNAME>oneadmin</GNAME><YEAR>2017</YEAR><MONTH>11</MONTH><CPU_COST>7.21</CPU_COST><MEMORY_COST>2.21</MEMORY_COST><DISK_COST>404.59</DISK_COST><TOTAL_COST>414.02</TOTAL_COST><HOURS>721</HOURS></SHOWBACK>`

---

<div class="post-metadata">

**Author:** ![Brady\_Deetz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/brady_deetz/32/5506_2.png) [@Brady\_Deetz](https://forum.opennebula.io/u/Brady_Deetz)\
**Post date:** [December 13, 2017, 5:28am UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413/5 "2017-12-13T05:28:55Z")

</div>

I believe oneshowback is calculating based on MB instead of GB. The hover detail window in the Template creation wizard describes calculations for disks as being GB/hour.

But the code for oneshowback multiplies disk size by 1024.

In my case, I had a 40GB disk. 0.0000137 \* 40 \* 1024 \* 24 \* 30 == 404.02 which is close enough to the reported 404.59.

This is currently occurring on line 183 of oneacct\_helper.rb in commit 526d5ce7  
`OpenNebulaHelper.unit_to_str(total_disk_size * 1024.0, {})`

---

<div class="post-metadata">

**Author:** ![AbelC](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/abelc/32/5192_2.png) [@AbelC](https://forum.opennebula.io/u/AbelC)\
**Post date:** [December 20, 2017, 3:06pm UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413/6 "2017-12-20T15:06:59Z")

</div>

Hello @Brady_Deetz,

We are a little confused with all this. I do not know what the problem is or how to reproduce it.  
Could you please provide me the steps to reproduce this?

Thanks!

Note: opennebula calculates the showback in MB

---

<div class="post-metadata">

**Author:** ![Brady\_Deetz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/brady_deetz/32/5506_2.png) [@Brady\_Deetz](https://forum.opennebula.io/u/Brady_Deetz)\
**Post date:** [December 22, 2017, 10:20pm UTC](https://forum.opennebula.io/t/showback-incorrect-calculation/5413/7 "2017-12-22T22:20:58Z")

</div>

To reproduce this I simply assign a cost of .0000137/gb disk/hr. When the showback is calculated, the cost of storage is 1000x higher than expected because the cost calculator is calculating base on MB instead of GB, despite the template builder in sunstone saying “Cost of each GB per hour” when you hover over the description of the field.

When I changed my storage cost to 0.0000000137 calculations come to totals I want, but are mathematically incorrect if the calculator indeed is supposed to work based on GB/Hr.
