mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #55 from prometheus/feature/telemetry/retrieval-durations
Duration statistics for each target pool.
This commit is contained in:
commit
f47dfc458c
|
@ -38,7 +38,10 @@ var (
|
||||||
|
|
||||||
targetOperationLatencies = metrics.NewHistogram(networkLatencyHistogram)
|
targetOperationLatencies = metrics.NewHistogram(networkLatencyHistogram)
|
||||||
|
|
||||||
// TODO: Include durations partitioned by target pool intervals.
|
retrievalDurations = metrics.NewHistogram(&metrics.HistogramSpecification{
|
||||||
|
Starts: metrics.LogarithmicSizedBucketsFor(0, 10000),
|
||||||
|
BucketBuilder: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 100),
|
||||||
|
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99}})
|
||||||
|
|
||||||
targetOperations = metrics.NewCounter()
|
targetOperations = metrics.NewCounter()
|
||||||
)
|
)
|
||||||
|
@ -46,4 +49,5 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
registry.Register("prometheus_target_operations_total", "The total numbers of operations of the various targets that are being monitored.", registry.NilLabels, targetOperations)
|
registry.Register("prometheus_target_operations_total", "The total numbers of operations of the various targets that are being monitored.", registry.NilLabels, targetOperations)
|
||||||
registry.Register("prometheus_target_operation_latency_ms", "The latencies for various target operations.", registry.NilLabels, targetOperationLatencies)
|
registry.Register("prometheus_target_operation_latency_ms", "The latencies for various target operations.", registry.NilLabels, targetOperationLatencies)
|
||||||
|
registry.Register("prometheus_targetpool_duration_ms", "The durations for each TargetPool to retrieve state from all included entities.", registry.NilLabels, retrievalDurations)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
intervalKey = "interval"
|
||||||
|
)
|
||||||
|
|
||||||
type TargetPool struct {
|
type TargetPool struct {
|
||||||
done chan bool
|
done chan bool
|
||||||
targets []Target
|
|
||||||
manager TargetManager
|
manager TargetManager
|
||||||
|
targets []Target
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTargetPool(m TargetManager) (p *TargetPool) {
|
func NewTargetPool(m TargetManager) (p *TargetPool) {
|
||||||
|
@ -51,7 +55,7 @@ func (p *TargetPool) Run(results chan format.Result, interval time.Duration) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker:
|
case <-ticker:
|
||||||
p.runIteration(results)
|
p.runIteration(results, interval)
|
||||||
case <-p.done:
|
case <-p.done:
|
||||||
log.Printf("TargetPool exiting...")
|
log.Printf("TargetPool exiting...")
|
||||||
break
|
break
|
||||||
|
@ -70,8 +74,13 @@ func (p *TargetPool) runSingle(earliest time.Time, results chan format.Result, t
|
||||||
t.Scrape(earliest, results)
|
t.Scrape(earliest, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *TargetPool) runIteration(results chan format.Result) {
|
func (p *TargetPool) runIteration(results chan format.Result, interval time.Duration) {
|
||||||
for i := 0; i < p.Len(); i++ {
|
begin := time.Now()
|
||||||
|
|
||||||
|
targetCount := p.Len()
|
||||||
|
finished := make(chan bool, targetCount)
|
||||||
|
|
||||||
|
for i := 0; i < targetCount; i++ {
|
||||||
target := heap.Pop(p).(Target)
|
target := heap.Pop(p).(Target)
|
||||||
if target == nil {
|
if target == nil {
|
||||||
break
|
break
|
||||||
|
@ -88,6 +97,16 @@ func (p *TargetPool) runIteration(results chan format.Result) {
|
||||||
go func() {
|
go func() {
|
||||||
p.runSingle(now, results, target)
|
p.runSingle(now, results, target)
|
||||||
heap.Push(p, target)
|
heap.Push(p, target)
|
||||||
|
finished <- true
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < targetCount; i++ {
|
||||||
|
<-finished
|
||||||
|
}
|
||||||
|
|
||||||
|
close(finished)
|
||||||
|
|
||||||
|
duration := float64(time.Now().Sub(begin) / time.Millisecond)
|
||||||
|
retrievalDurations.Add(map[string]string{intervalKey: interval.String()}, duration)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue