Showback incorrect calculation

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 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

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

I upgraded to 5.4.5 using the following github release. 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

Am I applying the wrong upgrade?

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>

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, {})

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

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.