Skip to content

Commit

Permalink
update metric log
Browse files Browse the repository at this point in the history
  • Loading branch information
jabelone committed May 31, 2024
1 parent 9171ebf commit 4a8fd13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions memberportal/api_metrics/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def calculate_metrics():
.annotate(total=Count("state"))
.order_by("total")
)
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
name=Metric.MetricName.MEMBER_COUNT_TOTAL, data=profile_states
).full_clean()

# get the count of all the different subscription states
Expand All @@ -48,7 +48,8 @@ def calculate_metrics():
.order_by("total")
)
subscription_states_data = [
{item["subscription_status"]: item["total"]} for item in subscription_states
{"state": item["subscription_status"], "total": item["total"]}
for item in subscription_states
]
Metric.objects.create(
name=Metric.MetricName.SUBSCRIPTION_COUNT_TOTAL,
Expand Down
4 changes: 3 additions & 1 deletion memberportal/api_metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def post(self, request):
continue

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

return Response()

0 comments on commit 4a8fd13

Please sign in to comment.