diff --git a/admin-costs-plugin/garr_costs/content/costs/utils.py b/admin-costs-plugin/garr_costs/content/costs/utils.py index 3df3c1bc6590e913c7afd83a7dbe5aecf563cebe..0d51798b840cdf9280943abbb3b6750d35edba2d 100644 --- a/admin-costs-plugin/garr_costs/content/costs/utils.py +++ b/admin-costs-plugin/garr_costs/content/costs/utils.py @@ -49,13 +49,11 @@ def get_volume_usage(request, resource, price, usage_start, usage_end, gnocchi_c return cost, usage, unit -def get_instance_usage(resource, price, usage_start, usage_end): +def get_instance_usage(resource, price, usage_start, usage_end, gnocchi_client): unit = 'hour' - if usage_start == usage_end: - hours_interval = 24 - else: - hours_interval = get_hours(usage_start, usage_end) + cpu_util_measures = gnocchi_client.metric.get_measures(metric=resource['metrics']['cpu_util'],start=usage_start,stop=usage_end) + hours_interval = (len(cpu_util_measures)*5)/60 cost = '{0:.2f}'.format( round(hours_interval * price, 2) diff --git a/admin-costs-plugin/garr_costs/content/costs/views.py b/admin-costs-plugin/garr_costs/content/costs/views.py index abf670b255f3c959ecddb409c8b7c4ef54e1968e..6e7ea6b3478322a756a7eaf149916c36c1b006ec 100644 --- a/admin-costs-plugin/garr_costs/content/costs/views.py +++ b/admin-costs-plugin/garr_costs/content/costs/views.py @@ -124,7 +124,7 @@ class IndexView(tables.DataTableView): try: if resource['type'] == 'instance': - cost, usage, unit = get_instance_usage(resource, price, resource_usage_start, resource_usage_end) + cost, usage, unit = get_instance_usage(resource, price, resource_usage_start, resource_usage_end, client) resource_flavor = resource['flavor_name'] elif resource['type'] == 'volume': cost, usage, unit = get_volume_usage(self.request, resource, price, resource_usage_start, resource_usage_end, client) diff --git a/costs-plugin/garr_costs/content/costs/utils.py b/costs-plugin/garr_costs/content/costs/utils.py index 3df3c1bc6590e913c7afd83a7dbe5aecf563cebe..0d51798b840cdf9280943abbb3b6750d35edba2d 100644 --- a/costs-plugin/garr_costs/content/costs/utils.py +++ b/costs-plugin/garr_costs/content/costs/utils.py @@ -49,13 +49,11 @@ def get_volume_usage(request, resource, price, usage_start, usage_end, gnocchi_c return cost, usage, unit -def get_instance_usage(resource, price, usage_start, usage_end): +def get_instance_usage(resource, price, usage_start, usage_end, gnocchi_client): unit = 'hour' - if usage_start == usage_end: - hours_interval = 24 - else: - hours_interval = get_hours(usage_start, usage_end) + cpu_util_measures = gnocchi_client.metric.get_measures(metric=resource['metrics']['cpu_util'],start=usage_start,stop=usage_end) + hours_interval = (len(cpu_util_measures)*5)/60 cost = '{0:.2f}'.format( round(hours_interval * price, 2) diff --git a/costs-plugin/garr_costs/content/costs/views.py b/costs-plugin/garr_costs/content/costs/views.py index abf670b255f3c959ecddb409c8b7c4ef54e1968e..6e7ea6b3478322a756a7eaf149916c36c1b006ec 100644 --- a/costs-plugin/garr_costs/content/costs/views.py +++ b/costs-plugin/garr_costs/content/costs/views.py @@ -124,7 +124,7 @@ class IndexView(tables.DataTableView): try: if resource['type'] == 'instance': - cost, usage, unit = get_instance_usage(resource, price, resource_usage_start, resource_usage_end) + cost, usage, unit = get_instance_usage(resource, price, resource_usage_start, resource_usage_end, client) resource_flavor = resource['flavor_name'] elif resource['type'] == 'volume': cost, usage, unit = get_volume_usage(self.request, resource, price, resource_usage_start, resource_usage_end, client)