Skip to content

Commit

Permalink
Merge pull request #259 from nautobot/ltm1.6/fix-metrics
Browse files Browse the repository at this point in the history
Fix bug in the nautobot_lcm_hw_end_of_support_per_part_number metric.
  • Loading branch information
bradh11 authored Dec 29, 2023
2 parents 5d2b7bf + b9587ee commit 652af94
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions nautobot_device_lifecycle_mgmt/metrics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Nautobot Device LCM plugin application level metrics ."""
from datetime import datetime

from django.db.models import Case, Count, F, IntegerField, OuterRef, Q, Subquery, Value, When
from django.db.models import Count, F, IntegerField, OuterRef, Q, Subquery, Value
from django.db.models.functions import Coalesce
from nautobot.dcim.models import Device, DeviceType, InventoryItem, Site
from prometheus_client.core import GaugeMetricFamily
Expand Down Expand Up @@ -138,13 +138,7 @@ def metrics_lcm_hw_end_of_support(): # pylint: disable=too-many-locals
# Generate metrics with counts for out of support devices per device type
for part_number, model, device_count in (
DeviceType.objects.order_by()
.annotate(
num_devices=Case(
When(id__in=hw_end_of_support_device_types, then=Count("instances")),
default=0,
output_field=IntegerField(),
)
)
.annotate(num_devices=Count("instances", filter=Q(id__in=hw_end_of_support_device_types)))
.values_list("part_number", "model", "num_devices")
):
hw_end_of_support_part_number_gauge.add_metric(
Expand Down

0 comments on commit 652af94

Please sign in to comment.