From 224b951e63cd6b60b1f3a88bc47a44d1fe59ebbb Mon Sep 17 00:00:00 2001 From: Gaius Date: Wed, 15 Mar 2023 18:36:16 +0800 Subject: [PATCH] fix: stat DownloadPeerCount and DownloadPieceCount (#2180) Signed-off-by: Gaius --- scheduler/metrics/metrics.go | 4 ++-- scheduler/service/service_v2.go | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scheduler/metrics/metrics.go b/scheduler/metrics/metrics.go index fca25ca14..4ead31203 100644 --- a/scheduler/metrics/metrics.go +++ b/scheduler/metrics/metrics.go @@ -86,14 +86,14 @@ var ( Namespace: types.MetricsNamespace, Subsystem: types.SchedulerMetricsName, Name: "exchange_peer_total", - Help: "Counter of the number of the leaving peer.", + Help: "Counter of the number of the exchanging peer.", }) ExchangePeerFailureCount = promauto.NewCounter(prometheus.CounterOpts{ Namespace: types.MetricsNamespace, Subsystem: types.SchedulerMetricsName, Name: "exchange_peer_failure_total", - Help: "Counter of the number of failed of the leaving peer.", + Help: "Counter of the number of failed of the exchanging peer.", }) RegisterPeerCount = promauto.NewCounterVec(prometheus.CounterOpts{ diff --git a/scheduler/service/service_v2.go b/scheduler/service/service_v2.go index 72849e707..650de5278 100644 --- a/scheduler/service/service_v2.go +++ b/scheduler/service/service_v2.go @@ -869,8 +869,11 @@ func (v *V2) handleDownloadPeerFailedRequest(ctx context.Context, peerID string) // Handle task with peer failed request. peer.Task.UpdatedAt.Store(time.Now()) - // Collect DownloadPeerFailureCount and DownloadPeerDuration metrics. - metrics.DownloadPeerFailureCount.WithLabelValues(peer.CalculatePriority(v.dynconfig).String(), peer.Task.Type.String(), + // Collect DownloadPeerCount and DownloadPeerFailureCount metrics. + priority := peer.CalculatePriority(v.dynconfig) + metrics.DownloadPeerCount.WithLabelValues(priority.String(), peer.Task.Type.String(), + peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() + metrics.DownloadPeerFailureCount.WithLabelValues(priority.String(), peer.Task.Type.String(), peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() return nil @@ -896,8 +899,11 @@ func (v *V2) handleDownloadPeerBackToSourceFailedRequest(ctx context.Context, pe return status.Error(codes.Internal, err.Error()) } - // Collect DownloadPeerBackToSourceFailureCount and DownloadPeerDuration metrics. - metrics.DownloadPeerBackToSourceFailureCount.WithLabelValues(peer.CalculatePriority(v.dynconfig).String(), peer.Task.Type.String(), + // Collect DownloadPeerCount and DownloadPeerBackToSourceFailureCount metrics. + priority := peer.CalculatePriority(v.dynconfig) + metrics.DownloadPeerCount.WithLabelValues(priority.String(), peer.Task.Type.String(), + peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() + metrics.DownloadPeerBackToSourceFailureCount.WithLabelValues(priority.String(), peer.Task.Type.String(), peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() return nil @@ -1025,7 +1031,9 @@ func (v *V2) handleDownloadPieceFailedRequest(ctx context.Context, peerID string return status.Errorf(codes.NotFound, "peer %s not found", peerID) } - // Collect DownloadPieceFailureCount metrics. + // Collect DownloadPieceCount and DownloadPieceFailureCount metrics. + metrics.DownloadPieceCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(), + peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() metrics.DownloadPieceFailureCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(), peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() @@ -1062,7 +1070,9 @@ func (v *V2) handleDownloadPieceBackToSourceFailedRequest(ctx context.Context, p // Handle task with piece back-to-source failed request. peer.Task.UpdatedAt.Store(time.Now()) - // Collect DownloadPieceFailureCount metrics. + // Collect DownloadPieceCount and DownloadPieceFailureCount metrics. + metrics.DownloadPieceCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(), + peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() metrics.DownloadPieceFailureCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(), peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()