diff --git a/lightning/metric/metric.go b/lightning/metric/metric.go index 3fef6fa7e..b2a8c75cf 100644 --- a/lightning/metric/metric.go +++ b/lightning/metric/metric.go @@ -118,6 +118,14 @@ var ( Buckets: prometheus.ExponentialBuckets(0.001, 3.1622776601683795, 10), }, ) + ApplyWorkerSecondsHistogram = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Namespace: "lightning", + Name: "apply_worker_seconds", + Help: "time needed to apply a worker", + Buckets: prometheus.ExponentialBuckets(0.001, 3.1622776601683795, 10), + }, []string{"name"}, + ) BlockEncodeSecondsHistogram = prometheus.NewHistogram( prometheus.HistogramOpts{ Namespace: "lightning", @@ -167,6 +175,7 @@ func init() { prometheus.MustRegister(ChecksumSecondsHistogram) prometheus.MustRegister(ChunkParserReadRowSecondsHistogram) prometheus.MustRegister(ChunkParserReadBlockSecondsHistogram) + prometheus.MustRegister(ApplyWorkerSecondsHistogram) } func RecordTableCount(status string, err error) { diff --git a/lightning/worker/worker.go b/lightning/worker/worker.go index dbf034fee..bd6a9d614 100644 --- a/lightning/worker/worker.go +++ b/lightning/worker/worker.go @@ -2,6 +2,7 @@ package worker import ( "context" + "time" "github.com/pingcap/tidb-lightning/lightning/metric" ) @@ -31,8 +32,10 @@ func NewRestoreWorkerPool(ctx context.Context, limit int, name string) *RestoreW } func (pool *RestoreWorkerPool) Apply() *RestoreWorker { + start := time.Now() worker := <-pool.workers metric.IdleWorkersGauge.WithLabelValues(pool.name).Set(float64(len(pool.workers))) + metric.ApplyWorkerSecondsHistogram.WithLabelValues(pool.name).Observe(time.Since(start).Seconds()) return worker } func (pool *RestoreWorkerPool) Recycle(worker *RestoreWorker) {