mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add session name to the metrics
This commit is contained in:
parent
fead99aaa6
commit
80fc10a1fd
|
@ -9,6 +9,7 @@ var (
|
||||||
Help: "bbgo exchange session connection status",
|
Help: "bbgo exchange session connection status",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"channel", // channel: user or market
|
"channel", // channel: user or market
|
||||||
"margin_type", // margin type: none, margin or isolated
|
"margin_type", // margin type: none, margin or isolated
|
||||||
|
@ -22,6 +23,7 @@ var (
|
||||||
Help: "bbgo exchange locked balances",
|
Help: "bbgo exchange locked balances",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. 1 or 0
|
"margin_type", // margin of connection. 1 or 0
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -35,6 +37,7 @@ var (
|
||||||
Help: "bbgo exchange available balances",
|
Help: "bbgo exchange available balances",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -48,6 +51,7 @@ var (
|
||||||
Help: "bbgo exchange balance debt",
|
Help: "bbgo exchange balance debt",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -61,6 +65,7 @@ var (
|
||||||
Help: "bbgo exchange balance borrowed",
|
Help: "bbgo exchange balance borrowed",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -74,6 +79,7 @@ var (
|
||||||
Help: "bbgo exchange balance interest",
|
Help: "bbgo exchange balance interest",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -87,6 +93,7 @@ var (
|
||||||
Help: "bbgo exchange session total net balances",
|
Help: "bbgo exchange session total net balances",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -100,6 +107,7 @@ var (
|
||||||
Help: "bbgo exchange session total balances",
|
Help: "bbgo exchange session total balances",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -113,6 +121,7 @@ var (
|
||||||
Help: "bbgo exchange session trades",
|
Help: "bbgo exchange session trades",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -127,6 +136,7 @@ var (
|
||||||
Help: "bbgo trading volume",
|
Help: "bbgo trading volume",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"symbol", // margin symbol of the connection.
|
"symbol", // margin symbol of the connection.
|
||||||
|
@ -141,6 +151,7 @@ var (
|
||||||
Help: "bbgo last update time of different channel",
|
Help: "bbgo last update time of different channel",
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
|
"session",
|
||||||
"exchange", // exchange name
|
"exchange", // exchange name
|
||||||
"margin_type", // margin of connection. none, margin or isolated
|
"margin_type", // margin of connection. none, margin or isolated
|
||||||
"channel", // channel: user, market
|
"channel", // channel: user, market
|
||||||
|
|
|
@ -901,10 +901,11 @@ func (session *ExchangeSession) MarginType() types.MarginType {
|
||||||
func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap) {
|
func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap) {
|
||||||
for currency, balance := range balances {
|
for currency, balance := range balances {
|
||||||
labels := prometheus.Labels{
|
labels := prometheus.Labels{
|
||||||
"exchange": session.ExchangeName.String(),
|
"session": session.Name,
|
||||||
"margin": string(session.MarginType()),
|
"exchange": session.ExchangeName.String(),
|
||||||
"symbol": session.IsolatedMarginSymbol,
|
"margin_type": string(session.MarginType()),
|
||||||
"currency": currency,
|
"symbol": session.IsolatedMarginSymbol,
|
||||||
|
"currency": currency,
|
||||||
}
|
}
|
||||||
|
|
||||||
metricsTotalBalances.With(labels).Set(balance.Total().Float64())
|
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())
|
metricsBalanceInterestMetrics.With(labels).Set(balance.Interest.Float64())
|
||||||
|
|
||||||
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"channel": "user",
|
"channel": "user",
|
||||||
|
@ -931,6 +933,7 @@ func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap
|
||||||
|
|
||||||
func (session *ExchangeSession) metricsOrderUpdater(order types.Order) {
|
func (session *ExchangeSession) metricsOrderUpdater(order types.Order) {
|
||||||
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"channel": "user",
|
"channel": "user",
|
||||||
|
@ -942,6 +945,7 @@ func (session *ExchangeSession) metricsOrderUpdater(order types.Order) {
|
||||||
|
|
||||||
func (session *ExchangeSession) metricsTradeUpdater(trade types.Trade) {
|
func (session *ExchangeSession) metricsTradeUpdater(trade types.Trade) {
|
||||||
labels := prometheus.Labels{
|
labels := prometheus.Labels{
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"side": trade.Side.String(),
|
"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())
|
metricsTradingVolume.With(labels).Add(trade.Quantity.Mul(trade.Price).Float64())
|
||||||
metricsTradesTotal.With(labels).Inc()
|
metricsTradesTotal.With(labels).Inc()
|
||||||
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"channel": "user",
|
"channel": "user",
|
||||||
|
@ -963,6 +968,7 @@ func (session *ExchangeSession) metricsTradeUpdater(trade types.Trade) {
|
||||||
func (session *ExchangeSession) bindMarketDataStreamMetrics(stream types.Stream) {
|
func (session *ExchangeSession) bindMarketDataStreamMetrics(stream types.Stream) {
|
||||||
stream.OnBookUpdate(func(book types.SliceOrderBook) {
|
stream.OnBookUpdate(func(book types.SliceOrderBook) {
|
||||||
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"channel": "market",
|
"channel": "market",
|
||||||
|
@ -973,6 +979,7 @@ func (session *ExchangeSession) bindMarketDataStreamMetrics(stream types.Stream)
|
||||||
})
|
})
|
||||||
stream.OnKLineClosed(func(kline types.KLine) {
|
stream.OnKLineClosed(func(kline types.KLine) {
|
||||||
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
metricsLastUpdateTimeMetrics.With(prometheus.Labels{
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"channel": "market",
|
"channel": "market",
|
||||||
|
@ -991,6 +998,7 @@ func (session *ExchangeSession) bindUserDataStreamMetrics(stream types.Stream) {
|
||||||
stream.OnDisconnect(func() {
|
stream.OnDisconnect(func() {
|
||||||
metricsConnectionStatus.With(prometheus.Labels{
|
metricsConnectionStatus.With(prometheus.Labels{
|
||||||
"channel": "user",
|
"channel": "user",
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"symbol": session.IsolatedMarginSymbol,
|
"symbol": session.IsolatedMarginSymbol,
|
||||||
|
@ -999,6 +1007,7 @@ func (session *ExchangeSession) bindUserDataStreamMetrics(stream types.Stream) {
|
||||||
stream.OnConnect(func() {
|
stream.OnConnect(func() {
|
||||||
metricsConnectionStatus.With(prometheus.Labels{
|
metricsConnectionStatus.With(prometheus.Labels{
|
||||||
"channel": "user",
|
"channel": "user",
|
||||||
|
"session": session.Name,
|
||||||
"exchange": session.ExchangeName.String(),
|
"exchange": session.ExchangeName.String(),
|
||||||
"margin_type": string(session.MarginType()),
|
"margin_type": string(session.MarginType()),
|
||||||
"symbol": session.IsolatedMarginSymbol,
|
"symbol": session.IsolatedMarginSymbol,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user