diff --git a/.munch-o-matic.yaml b/.munch-o-matic.yaml index 5cd1a35..f386add 100644 --- a/.munch-o-matic.yaml +++ b/.munch-o-matic.yaml @@ -19,7 +19,7 @@ Core: schedule: "*/10 * * * * *" type: CheckBalance - name: Update Metrics - schedule: "*/10 * * * * *" + schedule: "0 * * * * *" type: UpdateMetrics - name: Order Food params: diff --git a/core/daemon.go b/core/daemon.go index ccb9ca3..2b57bf0 100644 --- a/core/daemon.go +++ b/core/daemon.go @@ -194,7 +194,12 @@ func (d Daemon) updateMetrics(ch chan jobStatus) func() { ch <- jobStatus{JobId: jobId, Err: fmt.Errorf("could not load user: %w", err)} return } - UpdateAccountBalance(user.User.ID, user.User.FirstName, user.User.Customer.AccountBalance.Amount) + + totalPayed := 0 + for _, i := range user.User.Customer.Bookings { + totalPayed += i.BookingPrice + } + UpdatePaymentsTotal(user.User.ID, user.User.FirstName, totalPayed) } } diff --git a/core/metrics.go b/core/metrics.go index 9f3b738..f42e7cc 100644 --- a/core/metrics.go +++ b/core/metrics.go @@ -20,10 +20,17 @@ var accountBalance = prometheus.NewGaugeVec(prometheus.GaugeOpts{ []string{"user_id", "user_name"}, ) +var paymentsTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "payments_total", + Help: "Tracks total payments"}, + []string{"user_id", "user_name"}, +) + func init() { // Register metrics with Prometheus's default registry. prometheus.MustRegister(dishOrders) prometheus.MustRegister(accountBalance) + prometheus.MustRegister(paymentsTotal) } func UpdateOrdersPlaced(OrderId int, DishName string, NumOrders int) { @@ -34,6 +41,10 @@ func UpdateAccountBalance(UserId int, UserName string, Balance int) { accountBalance.With(prometheus.Labels{"user_id": fmt.Sprint(UserId), "user_name": UserName}).Set(float64(Balance)) } +func UpdatePaymentsTotal(UserId int, UserName string, Value int) { + paymentsTotal.With(prometheus.Labels{"user_id": fmt.Sprint(UserId), "user_name": UserName}).Set(float64(Value)) +} + // GetPrometheusHandler returns the HTTP handler for Prometheus metrics. func GetPrometheusHandler() http.Handler { return promhttp.Handler()