diff --git a/core/daemon.go b/core/daemon.go index 0c2b1b4..da469c8 100644 --- a/core/daemon.go +++ b/core/daemon.go @@ -187,5 +187,6 @@ func (d Daemon) updateMetrics(ch chan jobStatus) func() { UpdateOrdersPlaced(dish.OrderId, dish.Dish.Name, dish.Orders) } } + } } diff --git a/core/metrics.go b/core/metrics.go index 1d53381..9f3b738 100644 --- a/core/metrics.go +++ b/core/metrics.go @@ -1,26 +1,37 @@ package core import ( + "fmt" "net/http" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) -// ordersPlaced is a Prometheus counter metric. var dishOrders = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "total_orders_per_dish", - Help: "Total number of orders per dish orderID"}, - []string{"OrderId", "DishName"}, + Help: "Total number of orders per dish"}, + []string{"order_id", "dish_name"}, +) + +var accountBalance = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "account_balance", + Help: "Account balance in cent"}, + []string{"user_id", "user_name"}, ) func init() { // Register metrics with Prometheus's default registry. prometheus.MustRegister(dishOrders) + prometheus.MustRegister(accountBalance) } func UpdateOrdersPlaced(OrderId int, DishName string, NumOrders int) { - dishOrders.With(prometheus.Labels{"dish": DishName}).Set(float64(NumOrders)) + dishOrders.With(prometheus.Labels{"order_id": fmt.Sprint(OrderId), "dish_name": DishName}).Set(float64(NumOrders)) +} + +func UpdateAccountBalance(UserId int, UserName string, Balance int) { + accountBalance.With(prometheus.Labels{"user_id": fmt.Sprint(UserId), "user_name": UserName}).Set(float64(Balance)) } // GetPrometheusHandler returns the HTTP handler for Prometheus metrics.