diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py
index 9bee2291a..48c160dad 100644
--- a/netbox/dcim/models/racks.py
+++ b/netbox/dcim/models/racks.py
@@ -562,7 +562,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
if power_stats:
allocated_draw_total = sum(x['allocated_draw_total'] or 0 for x in power_stats)
available_power_total = sum(x['available_power'] for x in power_stats)
- return int(allocated_draw_total / available_power_total * 100) or (0, 0)
+ return (allocated_draw_total, available_power_total) or (0, 0)
return (0, 0)
diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py
index ba09475b0..77330044d 100644
--- a/netbox/ipam/tables.py
+++ b/netbox/ipam/tables.py
@@ -28,7 +28,7 @@ RIR_UTILIZATION = """
UTILIZATION_GRAPH = """
{% load helpers %}
-{% if record.pk %}{% utilization_graph record.get_utilization %}{% else %}—{% endif %}
+{% if record.pk %}{% utilization_graph record.get_utilization[0], record.get_utilization[1] %}{% else %}—{% endif %}
"""
ROLE_PREFIX_COUNT = """
diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html
index 4cf3b9018..511e27784 100644
--- a/netbox/templates/dcim/rack.html
+++ b/netbox/templates/dcim/rack.html
@@ -152,7 +152,7 @@
Utilization |
- {% utilization_graph rack.get_utilization %} |
+ {% utilization_graph rack.get_utilization[0] rack.get_utilization[1] %} |
diff --git a/netbox/templates/ipam/prefix.html b/netbox/templates/ipam/prefix.html
index 241cdd9a4..aa8242a89 100644
--- a/netbox/templates/ipam/prefix.html
+++ b/netbox/templates/ipam/prefix.html
@@ -183,7 +183,7 @@
Utilization |
- {% utilization_graph prefix.get_utilization %} |
+ {% utilization_graph prefix.get_utilization[0] prefix.get_utilization[1] %} |
diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py
index 2d25624e2..4ad42b97a 100644
--- a/netbox/utilities/templatetags/helpers.py
+++ b/netbox/utilities/templatetags/helpers.py
@@ -230,22 +230,22 @@ def querystring(request, **kwargs):
@register.inclusion_tag('utilities/templatetags/utilization_graph.html')
-def utilization_graph(data_input, warning_threshold=75, danger_threshold=90):
+def utilization_graph(used_count, total, warning_threshold=75, danger_threshold=90):
"""
Display a horizontal bar graph indicating a percentage of utilization.
"""
# Check for possible division by zero error
- if data_input[1] == 0:
+ if total == 0:
utilization = 0
else:
- utilization = int(float(data_input[0]) / data_input[1] * 100)
+ utilization = int(float(used_count) / total * 100)
return {
'utilization': utilization,
'warning_threshold': warning_threshold,
'danger_threshold': danger_threshold,
- 'utilization_count': data_input[0],
- 'total_count': data_input[1],
+ 'utilization_count': used_count,
+ 'total_count': total,
}