Skip to content

Commit

Permalink
add account balance metric
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkJD committed Dec 28, 2023
1 parent 63cf8ab commit b3b28b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,6 @@ func (d Daemon) updateMetrics(ch chan jobStatus) func() {
UpdateOrdersPlaced(dish.OrderId, dish.Dish.Name, dish.Orders)
}
}

}
}
19 changes: 15 additions & 4 deletions core/metrics.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit b3b28b2

Please sign in to comment.