Merge pull request #1831 from c9s/c9s/share-stream-book-metrics-labels

REFACTOR: share stream book metrics labels
This commit is contained in:
c9s 2024-11-18 14:14:55 +08:00 committed by GitHub
commit 11011726e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -202,11 +202,12 @@ func (sb *StreamOrderBook) updateMetrics(t time.Time) {
bestBid, bestAsk, ok := sb.BestBidAndAsk() bestBid, bestAsk, ok := sb.BestBidAndAsk()
if ok { if ok {
exchangeName := string(sb.Exchange) exchangeName := string(sb.Exchange)
streamOrderBookBestAskPriceMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestAsk.Price.Float64()) labels := prometheus.Labels{"symbol": sb.Symbol, "exchange": exchangeName}
streamOrderBookBestBidPriceMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestBid.Price.Float64()) streamOrderBookBestAskPriceMetrics.With(labels).Set(bestAsk.Price.Float64())
streamOrderBookBestAskVolumeMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestAsk.Volume.Float64()) streamOrderBookBestBidPriceMetrics.With(labels).Set(bestBid.Price.Float64())
streamOrderBookBestBidVolumeMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(bestBid.Volume.Float64()) streamOrderBookBestAskVolumeMetrics.With(labels).Set(bestAsk.Volume.Float64())
streamOrderBookUpdateTimeMetrics.WithLabelValues(sb.Symbol, exchangeName).Set(float64(t.UnixMilli())) streamOrderBookBestBidVolumeMetrics.With(labels).Set(bestBid.Volume.Float64())
streamOrderBookUpdateTimeMetrics.With(labels).Set(float64(t.UnixMilli()))
} }
} }