influxdb/storage/metrics.go

88 lines
2.4 KiB
Go
Raw Normal View History

2018-10-08 15:49:33 +00:00
package storage
import (
"sort"
"sync"
"github.com/prometheus/client_golang/prometheus"
)
2018-10-08 15:49:33 +00:00
// The following package variables act as singletons, to be shared by all
// storage.Engine instantiations. This allows multiple Engines to be
// monitored within the same process.
var (
rms *retentionMetrics
mmu sync.RWMutex
)
// RetentionPrometheusCollectors returns all prometheus metrics for retention.
func RetentionPrometheusCollectors() []prometheus.Collector {
mmu.RLock()
defer mmu.RUnlock()
var collectors []prometheus.Collector
if rms != nil {
collectors = append(collectors, rms.PrometheusCollectors()...)
}
return collectors
}
2018-10-08 15:49:33 +00:00
// namespace is the leading part of all published metrics for the Storage service.
const namespace = "storage"
const retentionSubsystem = "retention" // sub-system associated with metrics for writing points.
// retentionMetrics is a set of metrics concerned with tracking data about retention policies.
type retentionMetrics struct {
labels prometheus.Labels
2018-10-08 15:49:33 +00:00
Checks *prometheus.CounterVec
CheckDuration *prometheus.HistogramVec
}
func newRetentionMetrics(labels prometheus.Labels) *retentionMetrics {
var names []string
for k := range labels {
names = append(names, k)
}
sort.Strings(names)
2018-10-08 15:49:33 +00:00
2019-02-04 19:26:21 +00:00
checksNames := append(append([]string(nil), names...), "status", "org_id", "bucket_id")
sort.Strings(checksNames)
2018-10-08 15:49:33 +00:00
return &retentionMetrics{
2018-11-07 17:30:12 +00:00
labels: labels,
2018-10-08 15:49:33 +00:00
Checks: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: retentionSubsystem,
Name: "checks_total",
2019-02-04 19:26:21 +00:00
Help: "Number of retention check operations performed by org/bucket id.",
}, checksNames),
2018-10-08 15:49:33 +00:00
CheckDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: retentionSubsystem,
Name: "check_duration_seconds",
Help: "Time taken to perform a successful retention check.",
// 25 buckets spaced exponentially between 10s and ~2h
Buckets: prometheus.ExponentialBuckets(10, 1.32, 25),
}, names),
}
}
// Labels returns a copy of labels for use with retention metrics.
func (m *retentionMetrics) Labels() prometheus.Labels {
l := make(map[string]string, len(m.labels))
for k, v := range m.labels {
l[k] = v
}
return l
}
2018-10-08 15:49:33 +00:00
// PrometheusCollectors satisfies the prom.PrometheusCollector interface.
func (rm *retentionMetrics) PrometheusCollectors() []prometheus.Collector {
return []prometheus.Collector{
rm.Checks,
rm.CheckDuration,
}
}