Skip to content

Commit

Permalink
update metrics stored format
Browse files Browse the repository at this point in the history
  • Loading branch information
jabelone committed May 31, 2024
1 parent defd85f commit 9171ebf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
7 changes: 2 additions & 5 deletions memberportal/api_metrics/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def calculate_metrics():
.annotate(total=Count("state"))
.order_by("total")
)
profile_states_data = [
f"{item['state']}: {item['total']}" for item in profile_states
]
profile_states_data = [{item["state"]: item["total"]} for item in profile_states]
Metric.objects.create(
name=Metric.MetricName.MEMBER_COUNT_TOTAL, data=profile_states_data
).full_clean()
Expand All @@ -50,8 +48,7 @@ def calculate_metrics():
.order_by("total")
)
subscription_states_data = [
f"{item['subscription_status']}: {item['total']}"
for item in subscription_states
{item["subscription_status"]: item["total"]} for item in subscription_states
]
Metric.objects.create(
name=Metric.MetricName.SUBSCRIPTION_COUNT_TOTAL,
Expand Down
3 changes: 1 addition & 2 deletions memberportal/api_metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def post(self, request):

# get the latest metric for each type
for name in Metric.MetricName.values:
print(name)
metric = Metric.objects.filter(name=name).order_by("-creation_date").first()
if metric:
metrics.append(metric)
Expand All @@ -60,7 +59,7 @@ def post(self, request):
continue

for state in metric.data:
print(f"Setting {metric.name} {state['state']} to {state['total']}")
print(f"Setting {metric.name}:" + state)
prom_metric.labels(state=state["state"]).set(state["total"])

return Response()

0 comments on commit 9171ebf

Please sign in to comment.