bbgo: add session name to the metrics

This commit is contained in:
c9s 2024-08-21 15:36:35 +08:00
parent fead99aaa6
commit 80fc10a1fd
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 24 additions and 4 deletions

View File

@ -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

View File

@ -901,8 +901,9 @@ func (session *ExchangeSession) MarginType() types.MarginType {
func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap) {
for currency, balance := range balances {
labels := prometheus.Labels{
"session": session.Name,
"exchange": session.ExchangeName.String(),
"margin": string(session.MarginType()),
"margin_type": string(session.MarginType()),
"symbol": session.IsolatedMarginSymbol,
"currency": currency,
}
@ -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,