Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add asset & currency labels to purchase metrics #29

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 35 additions & 32 deletions src/main/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,47 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)

var assetLabels = []string{"asset", "asset_symbol"}
var currencyLabels = []string{"currency", "currency_symbol"}

func NewMetrics() Metrics {
return &MetricsImpl{
orderCounter: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "kraken_scheduler_orders_total",
Help: "The total number of orders made",
}, []string{"asset", "asset_symbol", "currency", "currency_symbol"}),
}, append(currencyLabels, assetLabels...)),
purchaseCounter: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "kraken_scheduler_purchases_total",
Help: "The total number of purchases made",
}, []string{"asset", "asset_symbol", "currency", "currency_symbol"}),
assetPurchaseAmountGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "kraken_scheduler_asset_purchase_amount",
}, append(currencyLabels, assetLabels...)),
purchaseAmountGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "kraken_scheduler_purchase_amount",
Help: "How much of an asset was purchased",
}, []string{"asset", "asset_symbol"}),
assetPurchaseAmountHistogram: promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "kraken_scheduler_asset_purchase_amount_history",
}, append(currencyLabels, assetLabels...)),
purchaseAmountHistogram: promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "kraken_scheduler_purchase_amount_history",
Help: "How much of an asset was purchased",
}, []string{"asset", "asset_symbol"}),
currencySpendAmountGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "kraken_scheduler_currency_spend_amount",
}, append(currencyLabels, assetLabels...)),
spendAmountGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "kraken_scheduler_spend_amount",
Help: "How much currency was spent on a purchase",
}, []string{"currency", "currency_symbol"}),
currencySpendAmountHistogram: promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "kraken_scheduler_currency_spend_amount_history",
}, append(currencyLabels, assetLabels...)),
spendAmountHistogram: promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "kraken_scheduler_spend_amount_history",
Help: "How much currency was spent on a purchase",
}, []string{"currency", "currency_symbol"}),
}, append(currencyLabels, assetLabels...)),
assetBalanceAmountGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "kraken_scheduler_asset_balance_amount",
Help: "How much of an asset currently exists on the account",
}, []string{"asset", "asset_symbol"}),
}, assetLabels),
assetBalanceValueGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "kraken_scheduler_asset_balance_value",
Help: "How much value of an asset exists on the account",
}, []string{"asset", "asset_symbol"}),
}, assetLabels),
currencyBalanceAmountGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "kraken_scheduler_currency_balance_amount",
Help: "How much of a currency currently exists on the account",
}, []string{"currency", "currency_symbol"}),
}, currencyLabels),
errorsCounter: promauto.NewCounter(prometheus.CounterOpts{
Name: "kraken_scheduler_errors_total",
Help: "The total number of errors during purchase process",
Expand All @@ -64,17 +67,17 @@ type Metrics interface {
}

type MetricsImpl struct {
orderCounter *prometheus.CounterVec
purchaseCounter *prometheus.CounterVec
assetPurchaseAmountGauge *prometheus.GaugeVec
assetPurchaseAmountHistogram *prometheus.HistogramVec
currencySpendAmountGauge *prometheus.GaugeVec
currencySpendAmountHistogram *prometheus.HistogramVec
assetBalanceAmountGauge *prometheus.GaugeVec
assetBalanceValueGauge *prometheus.GaugeVec
currencyBalanceAmountGauge *prometheus.GaugeVec
errorsCounter prometheus.Counter
retriesCounter prometheus.Counter
orderCounter *prometheus.CounterVec
purchaseCounter *prometheus.CounterVec
purchaseAmountGauge *prometheus.GaugeVec
purchaseAmountHistogram *prometheus.HistogramVec
spendAmountGauge *prometheus.GaugeVec
spendAmountHistogram *prometheus.HistogramVec
assetBalanceAmountGauge *prometheus.GaugeVec
assetBalanceValueGauge *prometheus.GaugeVec
currencyBalanceAmountGauge *prometheus.GaugeVec
errorsCounter prometheus.Counter
retriesCounter prometheus.Counter
}

func (m *MetricsImpl) LogOrder(pair model.Pair) {
Expand All @@ -83,10 +86,10 @@ func (m *MetricsImpl) LogOrder(pair model.Pair) {

func (m *MetricsImpl) LogPurchase(pair model.Pair, amount float64, fiatAmount float64, holdings float64, holdingsValue float64) {
m.purchaseCounter.WithLabelValues(pair.First.Name, pair.First.Symbol, pair.Second.Name, pair.Second.Symbol).Inc()
m.assetPurchaseAmountGauge.WithLabelValues(pair.First.Name, pair.First.Symbol).Set(amount)
m.assetPurchaseAmountHistogram.WithLabelValues(pair.First.Name, pair.First.Symbol).Observe(amount)
m.currencySpendAmountGauge.WithLabelValues(pair.Second.Name, pair.Second.Symbol).Set(fiatAmount)
m.currencySpendAmountHistogram.WithLabelValues(pair.Second.Name, pair.Second.Symbol).Observe(fiatAmount)
m.purchaseAmountGauge.WithLabelValues(pair.First.Name, pair.First.Symbol, pair.Second.Name, pair.Second.Symbol).Set(amount)
m.purchaseAmountHistogram.WithLabelValues(pair.First.Name, pair.First.Symbol, pair.Second.Name, pair.Second.Symbol).Observe(amount)
m.spendAmountGauge.WithLabelValues(pair.Second.Name, pair.Second.Symbol, pair.Second.Name, pair.Second.Symbol).Set(fiatAmount)
m.spendAmountHistogram.WithLabelValues(pair.Second.Name, pair.Second.Symbol, pair.Second.Name, pair.Second.Symbol).Observe(fiatAmount)
m.assetBalanceAmountGauge.WithLabelValues(pair.First.Name, pair.First.Symbol).Set(holdings)
m.assetBalanceValueGauge.WithLabelValues(pair.First.Name, pair.First.Symbol).Set(holdingsValue)
}
Expand Down
Loading