From e497b8b5e569a744c5e02060f379b633196b2b84 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 18 Nov 2024 14:03:41 +0800 Subject: [PATCH] types: share stream book metrics labels --- pkg/types/orderbook.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/types/orderbook.go b/pkg/types/orderbook.go index 0653fab68..0134cfbd0 100644 --- a/pkg/types/orderbook.go +++ b/pkg/types/orderbook.go @@ -202,11 +202,12 @@ func (sb *StreamOrderBook) updateMetrics(t time.Time) { bestBid, bestAsk, ok := sb.BestBidAndAsk() if ok { exchangeName := string(sb.Exchange) - streamOrderBookBestAskPriceMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestAsk.Price.Float64()) - streamOrderBookBestBidPriceMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestBid.Price.Float64()) - streamOrderBookBestAskVolumeMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestAsk.Volume.Float64()) - streamOrderBookBestBidVolumeMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestBid.Volume.Float64()) - streamOrderBookUpdateTimeMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(float64(t.UnixMilli())) + labels := prometheus.Labels{"symbol": sb.Symbol, "exchange": exchangeName} + streamOrderBookBestAskPriceMetrics.With(labels).Set(bestAsk.Price.Float64()) + streamOrderBookBestBidPriceMetrics.With(labels).Set(bestBid.Price.Float64()) + streamOrderBookBestAskVolumeMetrics.With(labels).Set(bestAsk.Volume.Float64()) + streamOrderBookBestBidVolumeMetrics.With(labels).Set(bestBid.Volume.Float64()) + streamOrderBookUpdateTimeMetrics.With(labels).Set(float64(t.UnixMilli())) } }