From 80fc10a1fde3570821103f18a90f245b5544d913 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 21 Aug 2024 15:36:35 +0800 Subject: [PATCH] bbgo: add session name to the metrics --- pkg/bbgo/metrics.go | 11 +++++++++++ pkg/bbgo/session.go | 17 +++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pkg/bbgo/metrics.go b/pkg/bbgo/metrics.go index 55f4cfab8..dd4a905d7 100644 --- a/pkg/bbgo/metrics.go +++ b/pkg/bbgo/metrics.go @@ -9,6 +9,7 @@ var ( Help: "bbgo exchange session connection status", }, []string{ + "session", "exchange", // exchange name "channel", // channel: user or market "margin_type", // margin type: none, margin or isolated @@ -22,6 +23,7 @@ var ( Help: "bbgo exchange locked balances", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. 1 or 0 "symbol", // margin symbol of the connection. @@ -35,6 +37,7 @@ var ( Help: "bbgo exchange available balances", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -48,6 +51,7 @@ var ( Help: "bbgo exchange balance debt", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -61,6 +65,7 @@ var ( Help: "bbgo exchange balance borrowed", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -74,6 +79,7 @@ var ( Help: "bbgo exchange balance interest", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -87,6 +93,7 @@ var ( Help: "bbgo exchange session total net balances", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -100,6 +107,7 @@ var ( Help: "bbgo exchange session total balances", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -113,6 +121,7 @@ var ( Help: "bbgo exchange session trades", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -127,6 +136,7 @@ var ( Help: "bbgo trading volume", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "symbol", // margin symbol of the connection. @@ -141,6 +151,7 @@ var ( Help: "bbgo last update time of different channel", }, []string{ + "session", "exchange", // exchange name "margin_type", // margin of connection. none, margin or isolated "channel", // channel: user, market diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 94279eb2d..328ce8bd9 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -901,10 +901,11 @@ func (session *ExchangeSession) MarginType() types.MarginType { func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap) { for currency, balance := range balances { labels := prometheus.Labels{ - "exchange": session.ExchangeName.String(), - "margin": string(session.MarginType()), - "symbol": session.IsolatedMarginSymbol, - "currency": currency, + "session": session.Name, + "exchange": session.ExchangeName.String(), + "margin_type": string(session.MarginType()), + "symbol": session.IsolatedMarginSymbol, + "currency": currency, } metricsTotalBalances.With(labels).Set(balance.Total().Float64()) @@ -918,6 +919,7 @@ func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap metricsBalanceInterestMetrics.With(labels).Set(balance.Interest.Float64()) metricsLastUpdateTimeMetrics.With(prometheus.Labels{ + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "channel": "user", @@ -931,6 +933,7 @@ func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap func (session *ExchangeSession) metricsOrderUpdater(order types.Order) { metricsLastUpdateTimeMetrics.With(prometheus.Labels{ + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "channel": "user", @@ -942,6 +945,7 @@ func (session *ExchangeSession) metricsOrderUpdater(order types.Order) { func (session *ExchangeSession) metricsTradeUpdater(trade types.Trade) { labels := prometheus.Labels{ + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "side": trade.Side.String(), @@ -951,6 +955,7 @@ func (session *ExchangeSession) metricsTradeUpdater(trade types.Trade) { metricsTradingVolume.With(labels).Add(trade.Quantity.Mul(trade.Price).Float64()) metricsTradesTotal.With(labels).Inc() metricsLastUpdateTimeMetrics.With(prometheus.Labels{ + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "channel": "user", @@ -963,6 +968,7 @@ func (session *ExchangeSession) metricsTradeUpdater(trade types.Trade) { func (session *ExchangeSession) bindMarketDataStreamMetrics(stream types.Stream) { stream.OnBookUpdate(func(book types.SliceOrderBook) { metricsLastUpdateTimeMetrics.With(prometheus.Labels{ + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "channel": "market", @@ -973,6 +979,7 @@ func (session *ExchangeSession) bindMarketDataStreamMetrics(stream types.Stream) }) stream.OnKLineClosed(func(kline types.KLine) { metricsLastUpdateTimeMetrics.With(prometheus.Labels{ + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "channel": "market", @@ -991,6 +998,7 @@ func (session *ExchangeSession) bindUserDataStreamMetrics(stream types.Stream) { stream.OnDisconnect(func() { metricsConnectionStatus.With(prometheus.Labels{ "channel": "user", + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "symbol": session.IsolatedMarginSymbol, @@ -999,6 +1007,7 @@ func (session *ExchangeSession) bindUserDataStreamMetrics(stream types.Stream) { stream.OnConnect(func() { metricsConnectionStatus.With(prometheus.Labels{ "channel": "user", + "session": session.Name, "exchange": session.ExchangeName.String(), "margin_type": string(session.MarginType()), "symbol": session.IsolatedMarginSymbol,