fix: stat DownloadPeerCount and DownloadPieceCount (#2180)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2023-03-15 18:36:16 +08:00
parent a2c7155751
commit 224b951e63
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
2 changed files with 18 additions and 8 deletions

View File

@ -86,14 +86,14 @@ var (
Namespace: types.MetricsNamespace, Namespace: types.MetricsNamespace,
Subsystem: types.SchedulerMetricsName, Subsystem: types.SchedulerMetricsName,
Name: "exchange_peer_total", 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{ ExchangePeerFailureCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: types.MetricsNamespace, Namespace: types.MetricsNamespace,
Subsystem: types.SchedulerMetricsName, Subsystem: types.SchedulerMetricsName,
Name: "exchange_peer_failure_total", 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{ RegisterPeerCount = promauto.NewCounterVec(prometheus.CounterOpts{

View File

@ -869,8 +869,11 @@ func (v *V2) handleDownloadPeerFailedRequest(ctx context.Context, peerID string)
// Handle task with peer failed request. // Handle task with peer failed request.
peer.Task.UpdatedAt.Store(time.Now()) peer.Task.UpdatedAt.Store(time.Now())
// Collect DownloadPeerFailureCount and DownloadPeerDuration metrics. // Collect DownloadPeerCount and DownloadPeerFailureCount metrics.
metrics.DownloadPeerFailureCount.WithLabelValues(peer.CalculatePriority(v.dynconfig).String(), peer.Task.Type.String(), 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() peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()
return nil return nil
@ -896,8 +899,11 @@ func (v *V2) handleDownloadPeerBackToSourceFailedRequest(ctx context.Context, pe
return status.Error(codes.Internal, err.Error()) return status.Error(codes.Internal, err.Error())
} }
// Collect DownloadPeerBackToSourceFailureCount and DownloadPeerDuration metrics. // Collect DownloadPeerCount and DownloadPeerBackToSourceFailureCount metrics.
metrics.DownloadPeerBackToSourceFailureCount.WithLabelValues(peer.CalculatePriority(v.dynconfig).String(), peer.Task.Type.String(), 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() peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()
return nil 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) 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(), metrics.DownloadPieceFailureCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() 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. // Handle task with piece back-to-source failed request.
peer.Task.UpdatedAt.Store(time.Now()) 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(), metrics.DownloadPieceFailureCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc() peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()