xmaker: fix buckets with prometheus.ExponentialBuckets and record cancel maker orders metrics

This commit is contained in:
c9s 2024-10-09 17:09:28 +08:00
parent f554d5f594
commit 11fcf8c617
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 10 additions and 4 deletions

View File

@ -6,12 +6,14 @@ var cancelOrderDurationMetrics = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Name: "xmaker_cancel_order_duration_milliseconds", Name: "xmaker_cancel_order_duration_milliseconds",
Help: "cancel order duration in milliseconds", Help: "cancel order duration in milliseconds",
Buckets: prometheus.ExponentialBuckets(50, 1.3, 10),
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) }, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
var makerOrderPlacementDurationMetrics = prometheus.NewHistogramVec( var makerOrderPlacementDurationMetrics = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Name: "xmaker_maker_order_placement_duration_milliseconds", Name: "xmaker_maker_order_placement_duration_milliseconds",
Help: "maker order placement duration in milliseconds", Help: "maker order placement duration in milliseconds",
Buckets: prometheus.ExponentialBuckets(50, 1.3, 10),
}, []string{"strategy_type", "strategy_id", "exchange", "symbol"}) }, []string{"strategy_type", "strategy_id", "exchange", "symbol"})
var openOrderBidExposureInUsdMetrics = prometheus.NewGaugeVec( var openOrderBidExposureInUsdMetrics = prometheus.NewGaugeVec(

View File

@ -546,12 +546,16 @@ func (s *Strategy) getLayerPrice(
} }
func (s *Strategy) updateQuote(ctx context.Context) error { func (s *Strategy) updateQuote(ctx context.Context) error {
cancelMakerOrdersProfile := timeprofile.Start("cancelMakerOrders")
if err := s.activeMakerOrders.GracefulCancel(ctx, s.makerSession.Exchange); err != nil { if err := s.activeMakerOrders.GracefulCancel(ctx, s.makerSession.Exchange); err != nil {
s.logger.Warnf("there are some %s orders not canceled, skipping placing maker orders", s.Symbol) s.logger.Warnf("there are some %s orders not canceled, skipping placing maker orders", s.Symbol)
s.activeMakerOrders.Print() s.activeMakerOrders.Print()
return nil return nil
} }
cancelOrderDurationMetrics.With(s.metricsLabels).Observe(float64(cancelMakerOrdersProfile.Stop().Milliseconds()))
if s.activeMakerOrders.NumOfOrders() > 0 { if s.activeMakerOrders.NumOfOrders() > 0 {
s.logger.Warnf("unable to cancel all %s orders, skipping placing maker orders", s.Symbol) s.logger.Warnf("unable to cancel all %s orders, skipping placing maker orders", s.Symbol)
return nil return nil