diff --git a/memberportal/api_metrics/tasks.py b/memberportal/api_metrics/tasks.py index a43a7ade..efb9619c 100644 --- a/memberportal/api_metrics/tasks.py +++ b/memberportal/api_metrics/tasks.py @@ -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 @@ -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, diff --git a/memberportal/api_metrics/views.py b/memberportal/api_metrics/views.py index bb1b24cf..e1240d1f 100644 --- a/memberportal/api_metrics/views.py +++ b/memberportal/api_metrics/views.py @@ -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()