mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Instrument indexing: queue length, batch sizes and latencies.
Change-Id: I60bcbd24b160e47d418a485d8cffa39344a257c6
This commit is contained in:
parent
aea32b0b4b
commit
a746fbb8bc
1
main.go
1
main.go
|
@ -141,6 +141,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal("Error opening disk persistence: ", err)
|
glog.Fatal("Error opening disk persistence: ", err)
|
||||||
}
|
}
|
||||||
|
registry.MustRegister(persistence)
|
||||||
|
|
||||||
o := &local.MemorySeriesStorageOptions{
|
o := &local.MemorySeriesStorageOptions{
|
||||||
Persistence: persistence,
|
Persistence: persistence,
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
clientmodel "github.com/prometheus/client_golang/model"
|
clientmodel "github.com/prometheus/client_golang/model"
|
||||||
|
|
||||||
|
@ -32,6 +33,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
namespace = "prometheus"
|
||||||
|
subsystem = "persistence"
|
||||||
|
|
||||||
seriesFileName = "series.db"
|
seriesFileName = "series.db"
|
||||||
seriesTempFileName = "series.db.tmp"
|
seriesTempFileName = "series.db.tmp"
|
||||||
|
|
||||||
|
@ -82,10 +86,15 @@ type diskPersistence struct {
|
||||||
indexingQueue chan indexingOp
|
indexingQueue chan indexingOp
|
||||||
indexingStopped chan struct{}
|
indexingStopped chan struct{}
|
||||||
indexingFlush chan chan int
|
indexingFlush chan chan int
|
||||||
|
|
||||||
|
indexingQueueLength prometheus.Gauge
|
||||||
|
indexingQueueCapacity prometheus.Metric
|
||||||
|
indexingBatchSizes prometheus.Summary
|
||||||
|
indexingBatchLatency prometheus.Summary
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDiskPersistence returns a newly allocated Persistence backed by local disk storage, ready to use.
|
// NewDiskPersistence returns a newly allocated Persistence backed by local disk storage, ready to use.
|
||||||
func NewDiskPersistence(basePath string, chunkLen int) (Persistence, error) {
|
func NewDiskPersistence(basePath string, chunkLen int) (*diskPersistence, error) {
|
||||||
if err := os.MkdirAll(basePath, 0700); err != nil {
|
if err := os.MkdirAll(basePath, 0700); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -119,11 +128,61 @@ func NewDiskPersistence(basePath string, chunkLen int) (Persistence, error) {
|
||||||
indexingQueue: make(chan indexingOp, indexingQueueCapacity),
|
indexingQueue: make(chan indexingOp, indexingQueueCapacity),
|
||||||
indexingStopped: make(chan struct{}),
|
indexingStopped: make(chan struct{}),
|
||||||
indexingFlush: make(chan chan int),
|
indexingFlush: make(chan chan int),
|
||||||
|
|
||||||
|
indexingQueueLength: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "indexing_queue_length",
|
||||||
|
Help: "The number of metrics waiting to be indexed.",
|
||||||
|
}),
|
||||||
|
indexingQueueCapacity: prometheus.MustNewConstMetric(
|
||||||
|
prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, subsystem, "indexing_queue_capacity"),
|
||||||
|
"The capacity of the indexing queue.",
|
||||||
|
nil, nil,
|
||||||
|
),
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
float64(indexingQueueCapacity),
|
||||||
|
),
|
||||||
|
indexingBatchSizes: prometheus.NewSummary(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "indexing_batch_sizes",
|
||||||
|
Help: "Quantiles for indexing batch sizes (number of metrics per batch).",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
indexingBatchLatency: prometheus.NewSummary(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "indexing_batch_latency_milliseconds",
|
||||||
|
Help: "Quantiles for batch indexing latencies in milliseconds.",
|
||||||
|
},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
go p.processIndexingQueue()
|
go p.processIndexingQueue()
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Describe implements prometheus.Collector.
|
||||||
|
func (p *diskPersistence) Describe(ch chan<- *prometheus.Desc) {
|
||||||
|
ch <- p.indexingQueueLength.Desc()
|
||||||
|
ch <- p.indexingQueueCapacity.Desc()
|
||||||
|
p.indexingBatchSizes.Describe(ch)
|
||||||
|
p.indexingBatchLatency.Describe(ch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect implements prometheus.Collector.
|
||||||
|
func (p *diskPersistence) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
p.indexingQueueLength.Set(float64(len(p.indexingQueue)))
|
||||||
|
|
||||||
|
ch <- p.indexingQueueLength
|
||||||
|
ch <- p.indexingQueueCapacity
|
||||||
|
p.indexingBatchSizes.Collect(ch)
|
||||||
|
p.indexingBatchLatency.Collect(ch)
|
||||||
|
}
|
||||||
|
|
||||||
// GetFingerprintsForLabelPair implements persistence.
|
// GetFingerprintsForLabelPair implements persistence.
|
||||||
func (p *diskPersistence) GetFingerprintsForLabelPair(lp metric.LabelPair) (clientmodel.Fingerprints, error) {
|
func (p *diskPersistence) GetFingerprintsForLabelPair(lp metric.LabelPair) (clientmodel.Fingerprints, error) {
|
||||||
fps, _, err := p.labelPairToFingerprints.Lookup(lp)
|
fps, _, err := p.labelPairToFingerprints.Lookup(lp)
|
||||||
|
@ -651,6 +710,10 @@ func (p *diskPersistence) processIndexingQueue() {
|
||||||
defer batchTimeout.Stop()
|
defer batchTimeout.Stop()
|
||||||
|
|
||||||
commitBatch := func() {
|
commitBatch := func() {
|
||||||
|
begin := time.Now()
|
||||||
|
defer p.indexingBatchLatency.Observe(float64(time.Since(begin) / time.Millisecond))
|
||||||
|
p.indexingBatchSizes.Observe(float64(batchSize))
|
||||||
|
|
||||||
if err := p.labelPairToFingerprints.IndexBatch(pairToFPs); err != nil {
|
if err := p.labelPairToFingerprints.IndexBatch(pairToFPs); err != nil {
|
||||||
glog.Error("Error indexing label pair to fingerprints batch: ", err)
|
glog.Error("Error indexing label pair to fingerprints batch: ", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue