2014-09-19 09:18:44 -07:00
|
|
|
// Copyright 2014 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2014-09-16 06:47:24 -07:00
|
|
|
// Package local contains the local time series storage used by Prometheus.
|
|
|
|
package local
|
2014-06-06 02:55:53 -07:00
|
|
|
|
|
|
|
import (
|
2014-11-13 11:50:25 -08:00
|
|
|
"container/list"
|
2014-10-23 06:18:32 -07:00
|
|
|
"sync/atomic"
|
2014-06-06 02:55:53 -07:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/glog"
|
2014-10-22 10:21:23 -07:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2014-06-06 02:55:53 -07:00
|
|
|
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
2014-10-22 10:21:23 -07:00
|
|
|
|
2014-06-06 02:55:53 -07:00
|
|
|
"github.com/prometheus/prometheus/storage/metric"
|
|
|
|
)
|
|
|
|
|
2014-11-05 11:02:45 -08:00
|
|
|
const (
|
2014-11-13 11:50:25 -08:00
|
|
|
persistQueueCap = 1024
|
|
|
|
evictRequestsCap = 1024
|
|
|
|
chunkLen = 1024
|
2014-11-13 07:55:15 -08:00
|
|
|
|
|
|
|
// See waitForNextFP.
|
|
|
|
fpMaxWaitDuration = 10 * time.Second
|
|
|
|
fpMinWaitDuration = 5 * time.Millisecond // ~ hard disk seek time.
|
|
|
|
fpMaxSweepTime = 6 * time.Hour
|
2014-11-13 11:50:25 -08:00
|
|
|
|
|
|
|
maxEvictInterval = time.Minute
|
|
|
|
headChunkTimeout = time.Hour // Close head chunk if not touched for that long.
|
2014-11-05 11:02:45 -08:00
|
|
|
)
|
2014-06-06 02:55:53 -07:00
|
|
|
|
|
|
|
type storageState uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
storageStarting storageState = iota
|
|
|
|
storageServing
|
|
|
|
storageStopping
|
|
|
|
)
|
|
|
|
|
2014-10-24 11:27:27 -07:00
|
|
|
type persistRequest struct {
|
|
|
|
fingerprint clientmodel.Fingerprint
|
|
|
|
chunkDesc *chunkDesc
|
|
|
|
}
|
2014-06-06 02:55:53 -07:00
|
|
|
|
2014-11-13 11:50:25 -08:00
|
|
|
type evictRequest struct {
|
|
|
|
cd *chunkDesc
|
|
|
|
evict bool
|
|
|
|
}
|
|
|
|
|
2014-10-24 11:27:27 -07:00
|
|
|
type memorySeriesStorage struct {
|
2014-10-27 12:40:48 -07:00
|
|
|
fpLocker *fingerprintLocker
|
|
|
|
fpToSeries *seriesMap
|
2014-06-06 02:55:53 -07:00
|
|
|
|
2014-10-24 11:27:27 -07:00
|
|
|
loopStopping, loopStopped chan struct{}
|
2014-11-13 11:50:25 -08:00
|
|
|
maxMemoryChunks int
|
2014-11-10 13:26:07 -08:00
|
|
|
purgeAfter time.Duration
|
2014-10-24 11:27:27 -07:00
|
|
|
checkpointInterval time.Duration
|
|
|
|
|
2014-10-27 12:40:48 -07:00
|
|
|
persistQueue chan persistRequest
|
2014-10-24 11:27:27 -07:00
|
|
|
persistStopped chan struct{}
|
|
|
|
persistence *persistence
|
|
|
|
|
2014-11-13 11:50:25 -08:00
|
|
|
evictList *list.List
|
|
|
|
evictRequests chan evictRequest
|
|
|
|
evictStopping, evictStopped chan struct{}
|
|
|
|
|
|
|
|
persistLatency prometheus.Summary
|
|
|
|
persistErrors *prometheus.CounterVec
|
|
|
|
persistQueueLength prometheus.Gauge
|
|
|
|
numSeries prometheus.Gauge
|
|
|
|
seriesOps *prometheus.CounterVec
|
|
|
|
ingestedSamplesCount prometheus.Counter
|
|
|
|
invalidPreloadRequestsCount prometheus.Counter
|
|
|
|
purgeDuration prometheus.Gauge
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 06:47:24 -07:00
|
|
|
// MemorySeriesStorageOptions contains options needed by
|
|
|
|
// NewMemorySeriesStorage. It is not safe to leave any of those at their zero
|
|
|
|
// values.
|
2014-06-06 02:55:53 -07:00
|
|
|
type MemorySeriesStorageOptions struct {
|
2014-11-13 11:50:25 -08:00
|
|
|
MemoryChunks int // How many chunks to keep in memory.
|
2014-10-07 10:11:24 -07:00
|
|
|
PersistenceStoragePath string // Location of persistence files.
|
2014-09-16 06:47:24 -07:00
|
|
|
PersistenceRetentionPeriod time.Duration // Chunks at least that old are purged.
|
2014-10-24 11:27:27 -07:00
|
|
|
CheckpointInterval time.Duration // How often to checkpoint the series map and head chunks.
|
2014-11-05 11:02:45 -08:00
|
|
|
Dirty bool // Force the storage to consider itself dirty on startup.
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 06:47:24 -07:00
|
|
|
// NewMemorySeriesStorage returns a newly allocated Storage. Storage.Serve still
|
|
|
|
// has to be called to start the storage.
|
2014-09-10 09:41:52 -07:00
|
|
|
func NewMemorySeriesStorage(o *MemorySeriesStorageOptions) (Storage, error) {
|
2014-11-05 11:02:45 -08:00
|
|
|
p, err := newPersistence(o.PersistenceStoragePath, chunkLen, o.Dirty)
|
2014-10-07 10:11:24 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-09-10 09:41:52 -07:00
|
|
|
glog.Info("Loading series map and head chunks...")
|
2014-10-27 12:40:48 -07:00
|
|
|
fpToSeries, err := p.loadSeriesMapAndHeads()
|
2014-09-10 09:41:52 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-10-27 12:40:48 -07:00
|
|
|
glog.Infof("%d series loaded.", fpToSeries.length())
|
2014-10-23 06:18:32 -07:00
|
|
|
numSeries := prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "memory_series",
|
|
|
|
Help: "The current number of series in memory.",
|
|
|
|
})
|
2014-10-27 12:40:48 -07:00
|
|
|
numSeries.Set(float64(fpToSeries.length()))
|
2014-06-06 02:55:53 -07:00
|
|
|
|
2014-09-10 09:41:52 -07:00
|
|
|
return &memorySeriesStorage{
|
2014-11-04 07:27:14 -08:00
|
|
|
fpLocker: newFingerprintLocker(256),
|
2014-10-27 12:40:48 -07:00
|
|
|
fpToSeries: fpToSeries,
|
2014-06-06 02:55:53 -07:00
|
|
|
|
2014-10-24 11:27:27 -07:00
|
|
|
loopStopping: make(chan struct{}),
|
|
|
|
loopStopped: make(chan struct{}),
|
2014-11-13 11:50:25 -08:00
|
|
|
maxMemoryChunks: o.MemoryChunks,
|
2014-10-24 11:27:27 -07:00
|
|
|
purgeAfter: o.PersistenceRetentionPeriod,
|
|
|
|
checkpointInterval: o.CheckpointInterval,
|
2014-06-06 02:55:53 -07:00
|
|
|
|
2014-10-27 12:40:48 -07:00
|
|
|
persistQueue: make(chan persistRequest, persistQueueCap),
|
2014-10-24 11:27:27 -07:00
|
|
|
persistStopped: make(chan struct{}),
|
|
|
|
persistence: p,
|
2014-10-23 06:18:32 -07:00
|
|
|
|
2014-11-13 11:50:25 -08:00
|
|
|
evictList: list.New(),
|
|
|
|
evictRequests: make(chan evictRequest, evictRequestsCap),
|
|
|
|
evictStopping: make(chan struct{}),
|
|
|
|
evictStopped: make(chan struct{}),
|
|
|
|
|
2014-10-23 06:18:32 -07:00
|
|
|
persistLatency: prometheus.NewSummary(prometheus.SummaryOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "persist_latency_microseconds",
|
|
|
|
Help: "A summary of latencies for persisting each chunk.",
|
|
|
|
}),
|
|
|
|
persistErrors: prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "persist_errors_total",
|
|
|
|
Help: "A counter of errors persisting chunks.",
|
|
|
|
},
|
|
|
|
[]string{"error"},
|
|
|
|
),
|
|
|
|
persistQueueLength: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "persist_queue_length",
|
|
|
|
Help: "The current number of chunks waiting in the persist queue.",
|
|
|
|
}),
|
|
|
|
numSeries: numSeries,
|
|
|
|
seriesOps: prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "series_ops_total",
|
|
|
|
Help: "The total number of series operations by their type.",
|
|
|
|
},
|
|
|
|
[]string{opTypeLabel},
|
|
|
|
),
|
|
|
|
ingestedSamplesCount: prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "ingested_samples_total",
|
|
|
|
Help: "The total number of samples ingested.",
|
|
|
|
}),
|
2014-11-05 11:02:45 -08:00
|
|
|
invalidPreloadRequestsCount: prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "invalid_preload_requests_total",
|
|
|
|
Help: "The total number of preload requests referring to a non-existent series. This is an indication of outdated label indexes.",
|
|
|
|
}),
|
2014-06-06 02:55:53 -07:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2014-10-24 11:27:27 -07:00
|
|
|
// Start implements Storage.
|
|
|
|
func (s *memorySeriesStorage) Start() {
|
2014-11-13 11:50:25 -08:00
|
|
|
go s.handleEvictList()
|
2014-10-24 11:27:27 -07:00
|
|
|
go s.handlePersistQueue()
|
|
|
|
go s.loop()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop implements Storage.
|
|
|
|
func (s *memorySeriesStorage) Stop() error {
|
2014-11-11 15:38:28 -08:00
|
|
|
glog.Info("Stopping local storage...")
|
2014-11-13 11:50:25 -08:00
|
|
|
|
2014-10-24 11:27:27 -07:00
|
|
|
glog.Info("Stopping maintenance loop...")
|
|
|
|
close(s.loopStopping)
|
|
|
|
<-s.loopStopped
|
|
|
|
|
2014-11-13 11:50:25 -08:00
|
|
|
glog.Info("Stopping persist queue...")
|
2014-10-24 11:27:27 -07:00
|
|
|
close(s.persistQueue)
|
|
|
|
<-s.persistStopped
|
|
|
|
|
2014-11-13 11:50:25 -08:00
|
|
|
glog.Info("Stopping chunk eviction...")
|
|
|
|
close(s.evictStopping)
|
|
|
|
<-s.evictStopped
|
|
|
|
|
2014-10-24 11:27:27 -07:00
|
|
|
// One final checkpoint of the series map and the head chunks.
|
2014-10-27 12:40:48 -07:00
|
|
|
if err := s.persistence.checkpointSeriesMapAndHeads(s.fpToSeries, s.fpLocker); err != nil {
|
2014-10-24 11:27:27 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.persistence.close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-11-11 15:38:28 -08:00
|
|
|
glog.Info("Local storage stopped.")
|
2014-10-24 11:27:27 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WaitForIndexing implements Storage.
|
|
|
|
func (s *memorySeriesStorage) WaitForIndexing() {
|
|
|
|
s.persistence.waitForIndexing()
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewIterator implements storage.
|
|
|
|
func (s *memorySeriesStorage) NewIterator(fp clientmodel.Fingerprint) SeriesIterator {
|
|
|
|
s.fpLocker.Lock(fp)
|
|
|
|
defer s.fpLocker.Unlock(fp)
|
|
|
|
|
2014-10-27 12:40:48 -07:00
|
|
|
series, ok := s.fpToSeries.get(fp)
|
2014-10-24 11:27:27 -07:00
|
|
|
if !ok {
|
|
|
|
// Oops, no series for fp found. That happens if, after
|
|
|
|
// preloading is done, the whole series is identified as old
|
|
|
|
// enough for purging and hence purged for good. As there is no
|
|
|
|
// data left to iterate over, return an iterator that will never
|
|
|
|
// return any values.
|
|
|
|
return nopSeriesIterator{}
|
|
|
|
}
|
|
|
|
return series.newIterator(
|
|
|
|
func() { s.fpLocker.Lock(fp) },
|
|
|
|
func() { s.fpLocker.Unlock(fp) },
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPreloader implements Storage.
|
|
|
|
func (s *memorySeriesStorage) NewPreloader() Preloader {
|
|
|
|
return &memorySeriesPreloader{
|
|
|
|
storage: s,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFingerprintsForLabelMatchers implements Storage.
|
|
|
|
func (s *memorySeriesStorage) GetFingerprintsForLabelMatchers(labelMatchers metric.LabelMatchers) clientmodel.Fingerprints {
|
|
|
|
var result map[clientmodel.Fingerprint]struct{}
|
|
|
|
for _, matcher := range labelMatchers {
|
|
|
|
intersection := map[clientmodel.Fingerprint]struct{}{}
|
|
|
|
switch matcher.Type {
|
|
|
|
case metric.Equal:
|
|
|
|
fps, err := s.persistence.getFingerprintsForLabelPair(
|
|
|
|
metric.LabelPair{
|
|
|
|
Name: matcher.Name,
|
|
|
|
Value: matcher.Value,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
glog.Error("Error getting fingerprints for label pair: ", err)
|
|
|
|
}
|
|
|
|
if len(fps) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
for _, fp := range fps {
|
|
|
|
if _, ok := result[fp]; ok || result == nil {
|
|
|
|
intersection[fp] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
values, err := s.persistence.getLabelValuesForLabelName(matcher.Name)
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Error getting label values for label name %q: %v", matcher.Name, err)
|
|
|
|
}
|
|
|
|
matches := matcher.Filter(values)
|
|
|
|
if len(matches) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
for _, v := range matches {
|
|
|
|
fps, err := s.persistence.getFingerprintsForLabelPair(
|
|
|
|
metric.LabelPair{
|
|
|
|
Name: matcher.Name,
|
|
|
|
Value: v,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
glog.Error("Error getting fingerprints for label pair: ", err)
|
|
|
|
}
|
|
|
|
for _, fp := range fps {
|
|
|
|
if _, ok := result[fp]; ok || result == nil {
|
|
|
|
intersection[fp] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(intersection) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
result = intersection
|
|
|
|
}
|
|
|
|
|
|
|
|
fps := make(clientmodel.Fingerprints, 0, len(result))
|
|
|
|
for fp := range result {
|
|
|
|
fps = append(fps, fp)
|
|
|
|
}
|
|
|
|
return fps
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelValuesForLabelName implements Storage.
|
|
|
|
func (s *memorySeriesStorage) GetLabelValuesForLabelName(labelName clientmodel.LabelName) clientmodel.LabelValues {
|
|
|
|
lvs, err := s.persistence.getLabelValuesForLabelName(labelName)
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Error getting label values for label name %q: %v", labelName, err)
|
|
|
|
}
|
|
|
|
return lvs
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMetricForFingerprint implements Storage.
|
|
|
|
func (s *memorySeriesStorage) GetMetricForFingerprint(fp clientmodel.Fingerprint) clientmodel.Metric {
|
|
|
|
s.fpLocker.Lock(fp)
|
|
|
|
defer s.fpLocker.Unlock(fp)
|
|
|
|
|
2014-10-27 12:40:48 -07:00
|
|
|
series, ok := s.fpToSeries.get(fp)
|
2014-10-24 11:27:27 -07:00
|
|
|
if ok {
|
|
|
|
// Copy required here because caller might mutate the returned
|
|
|
|
// metric.
|
|
|
|
m := make(clientmodel.Metric, len(series.metric))
|
|
|
|
for ln, lv := range series.metric {
|
|
|
|
m[ln] = lv
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
metric, err := s.persistence.getArchivedMetric(fp)
|
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Error retrieving archived metric for fingerprint %v: %v", fp, err)
|
|
|
|
}
|
|
|
|
return metric
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-09-19 09:18:44 -07:00
|
|
|
// AppendSamples implements Storage.
|
2014-06-06 02:55:53 -07:00
|
|
|
func (s *memorySeriesStorage) AppendSamples(samples clientmodel.Samples) {
|
|
|
|
for _, sample := range samples {
|
|
|
|
s.appendSample(sample)
|
|
|
|
}
|
|
|
|
|
2014-10-23 06:18:32 -07:00
|
|
|
s.ingestedSamplesCount.Add(float64(len(samples)))
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *memorySeriesStorage) appendSample(sample *clientmodel.Sample) {
|
2014-09-24 07:55:45 -07:00
|
|
|
fp := sample.Metric.Fingerprint()
|
2014-10-07 10:11:24 -07:00
|
|
|
s.fpLocker.Lock(fp)
|
2014-09-24 07:55:45 -07:00
|
|
|
series := s.getOrCreateSeries(fp, sample.Metric)
|
2014-10-27 12:40:48 -07:00
|
|
|
chunkDescsToPersist := series.add(fp, &metric.SamplePair{
|
2014-06-06 02:55:53 -07:00
|
|
|
Value: sample.Value,
|
|
|
|
Timestamp: sample.Timestamp,
|
2014-10-27 12:40:48 -07:00
|
|
|
})
|
|
|
|
s.fpLocker.Unlock(fp)
|
|
|
|
// Queue only outside of the locked area, processing the persistQueue
|
|
|
|
// requires the same lock!
|
|
|
|
for _, cd := range chunkDescsToPersist {
|
|
|
|
s.persistQueue <- persistRequest{fp, cd}
|
|
|
|
}
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-09-24 07:55:45 -07:00
|
|
|
func (s *memorySeriesStorage) getOrCreateSeries(fp clientmodel.Fingerprint, m clientmodel.Metric) *memorySeries {
|
2014-10-27 12:40:48 -07:00
|
|
|
series, ok := s.fpToSeries.get(fp)
|
2014-06-06 02:55:53 -07:00
|
|
|
if !ok {
|
2014-11-05 11:02:45 -08:00
|
|
|
unarchived, firstTime, err := s.persistence.unarchiveMetric(fp)
|
2014-09-10 09:41:52 -07:00
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("Error unarchiving fingerprint %v: %v", fp, err)
|
|
|
|
}
|
2014-10-22 10:21:23 -07:00
|
|
|
if unarchived {
|
2014-10-23 06:18:32 -07:00
|
|
|
s.seriesOps.WithLabelValues(unarchive).Inc()
|
2014-10-22 10:21:23 -07:00
|
|
|
} else {
|
2014-09-10 09:41:52 -07:00
|
|
|
// This was a genuinely new series, so index the metric.
|
2014-10-28 11:01:41 -07:00
|
|
|
s.persistence.indexMetric(fp, m)
|
2014-10-23 06:18:32 -07:00
|
|
|
s.seriesOps.WithLabelValues(create).Inc()
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
2014-11-05 11:02:45 -08:00
|
|
|
series = newMemorySeries(m, !unarchived, firstTime)
|
2014-10-27 12:40:48 -07:00
|
|
|
s.fpToSeries.put(fp, series)
|
2014-10-23 06:18:32 -07:00
|
|
|
s.numSeries.Inc()
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
return series
|
|
|
|
}
|
|
|
|
|
2014-10-15 06:53:05 -07:00
|
|
|
func (s *memorySeriesStorage) preloadChunksForRange(
|
|
|
|
fp clientmodel.Fingerprint,
|
|
|
|
from clientmodel.Timestamp, through clientmodel.Timestamp,
|
|
|
|
stalenessDelta time.Duration,
|
|
|
|
) ([]*chunkDesc, error) {
|
2014-10-07 10:11:24 -07:00
|
|
|
s.fpLocker.Lock(fp)
|
|
|
|
defer s.fpLocker.Unlock(fp)
|
2014-09-16 06:47:24 -07:00
|
|
|
|
2014-10-27 12:40:48 -07:00
|
|
|
series, ok := s.fpToSeries.get(fp)
|
2014-06-06 02:55:53 -07:00
|
|
|
if !ok {
|
2014-10-07 10:11:24 -07:00
|
|
|
has, first, last, err := s.persistence.hasArchivedMetric(fp)
|
2014-09-16 06:47:24 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if !has {
|
2014-11-05 11:02:45 -08:00
|
|
|
s.invalidPreloadRequestsCount.Inc()
|
|
|
|
return nil, nil
|
2014-09-16 06:47:24 -07:00
|
|
|
}
|
|
|
|
if from.Add(-stalenessDelta).Before(last) && through.Add(stalenessDelta).After(first) {
|
2014-10-07 10:11:24 -07:00
|
|
|
metric, err := s.persistence.getArchivedMetric(fp)
|
2014-09-16 06:47:24 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-09-24 07:55:45 -07:00
|
|
|
series = s.getOrCreateSeries(fp, metric)
|
2014-10-13 09:55:46 -07:00
|
|
|
} else {
|
|
|
|
return nil, nil
|
2014-09-16 06:47:24 -07:00
|
|
|
}
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
2014-11-13 11:50:25 -08:00
|
|
|
return series.preloadChunksForRange(from, through, fp, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *memorySeriesStorage) handleEvictList() {
|
|
|
|
ticker := time.NewTicker(maxEvictInterval)
|
|
|
|
count := 0
|
|
|
|
loop:
|
|
|
|
for {
|
|
|
|
// To batch up evictions a bit, this tries evictions at least
|
|
|
|
// once per evict interval, but earlier if the number of evict
|
2014-11-20 12:03:51 -08:00
|
|
|
// requests with evict==true that have happened since the last
|
2014-11-13 11:50:25 -08:00
|
|
|
// evict run is more than maxMemoryChunks/1000.
|
|
|
|
select {
|
|
|
|
case req := <-s.evictRequests:
|
|
|
|
if req.evict {
|
|
|
|
req.cd.evictListElement = s.evictList.PushBack(req.cd)
|
|
|
|
count++
|
|
|
|
if count > s.maxMemoryChunks/1000 {
|
|
|
|
s.maybeEvict()
|
|
|
|
count = 0
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if req.cd.evictListElement != nil {
|
|
|
|
s.evictList.Remove(req.cd.evictListElement)
|
|
|
|
req.cd.evictListElement = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case <-ticker.C:
|
|
|
|
if s.evictList.Len() > 0 {
|
|
|
|
s.maybeEvict()
|
|
|
|
}
|
|
|
|
case <-s.evictStopping:
|
|
|
|
break loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ticker.Stop()
|
|
|
|
glog.Info("Chunk eviction stopped.")
|
|
|
|
close(s.evictStopped)
|
|
|
|
}
|
|
|
|
|
|
|
|
// maybeEvict is a local helper method. Must only be called by handleEvictList.
|
|
|
|
func (s *memorySeriesStorage) maybeEvict() {
|
|
|
|
numChunksToEvict := int(atomic.LoadInt64(&numMemChunks)) - s.maxMemoryChunks
|
|
|
|
if numChunksToEvict <= 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
chunkDescsToEvict := make([]*chunkDesc, numChunksToEvict)
|
|
|
|
for i := range chunkDescsToEvict {
|
|
|
|
e := s.evictList.Front()
|
|
|
|
if e == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
cd := e.Value.(*chunkDesc)
|
|
|
|
cd.evictListElement = nil
|
|
|
|
chunkDescsToEvict[i] = cd
|
|
|
|
s.evictList.Remove(e)
|
|
|
|
}
|
|
|
|
// Do the actual eviction in a goroutine as we might otherwise deadlock,
|
|
|
|
// in the following way: A chunk was unpinned completely and therefore
|
|
|
|
// scheduled for eviction. At the time we actually try to evict it,
|
|
|
|
// another goroutine is pinning the chunk. The pinning goroutine has
|
|
|
|
// currently locked the chunk and tries to send the evict request (to
|
|
|
|
// remove the chunk from the evict list) to the evictRequests
|
|
|
|
// channel. The send blocks because evictRequests is full. However, the
|
2014-11-20 12:03:51 -08:00
|
|
|
// goroutine that is supposed to empty the channel is waiting for the
|
2014-11-13 11:50:25 -08:00
|
|
|
// chunkDesc lock to try to evict the chunk.
|
|
|
|
go func() {
|
|
|
|
for _, cd := range chunkDescsToEvict {
|
|
|
|
if cd == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
cd.maybeEvict()
|
|
|
|
// We don't care if the eviction succeeds. If the chunk
|
|
|
|
// was pinned in the meantime, it will be added to the
|
|
|
|
// evict list once it gets unpinned again.
|
|
|
|
}
|
|
|
|
}()
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *memorySeriesStorage) handlePersistQueue() {
|
|
|
|
for req := range s.persistQueue {
|
2014-10-23 06:18:32 -07:00
|
|
|
s.persistQueueLength.Set(float64(len(s.persistQueue)))
|
2014-06-06 02:55:53 -07:00
|
|
|
start := time.Now()
|
2014-10-27 12:40:48 -07:00
|
|
|
s.fpLocker.Lock(req.fingerprint)
|
|
|
|
offset, err := s.persistence.persistChunk(req.fingerprint, req.chunkDesc.chunk)
|
|
|
|
if series, seriesInMemory := s.fpToSeries.get(req.fingerprint); err == nil && seriesInMemory && series.chunkDescsOffset == -1 {
|
|
|
|
// This is the first chunk persisted for a newly created
|
|
|
|
// series that had prior chunks on disk. Finally, we can
|
|
|
|
// set the chunkDescsOffset.
|
|
|
|
series.chunkDescsOffset = offset
|
|
|
|
}
|
|
|
|
s.fpLocker.Unlock(req.fingerprint)
|
2014-10-23 06:18:32 -07:00
|
|
|
s.persistLatency.Observe(float64(time.Since(start)) / float64(time.Microsecond))
|
2014-06-06 02:55:53 -07:00
|
|
|
if err != nil {
|
2014-10-23 06:18:32 -07:00
|
|
|
s.persistErrors.WithLabelValues(err.Error()).Inc()
|
2014-10-27 12:40:48 -07:00
|
|
|
glog.Error("Error persisting chunk: ", err)
|
2014-11-05 11:02:45 -08:00
|
|
|
s.persistence.setDirty(true)
|
2014-06-06 02:55:53 -07:00
|
|
|
continue
|
|
|
|
}
|
2014-11-13 11:50:25 -08:00
|
|
|
req.chunkDesc.unpin(s.evictRequests)
|
2014-10-22 10:21:23 -07:00
|
|
|
chunkOps.WithLabelValues(persistAndUnpin).Inc()
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
2014-11-13 11:50:25 -08:00
|
|
|
glog.Info("Persist queue drained and stopped.")
|
2014-10-24 11:27:27 -07:00
|
|
|
close(s.persistStopped)
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-10 13:26:07 -08:00
|
|
|
// waitForNextFP waits an estimated duration, after which we want to process
|
|
|
|
// another fingerprint so that we will process all fingerprints in a tenth of
|
2014-11-13 07:55:15 -08:00
|
|
|
// s.purgeAfter assuming that the system is doing nothing else, e.g. if we want
|
|
|
|
// to purge after 40h, we want to cycle through all fingerprints within
|
|
|
|
// 4h. However, the maximum sweep time is capped at fpMaxSweepTime. Furthermore,
|
|
|
|
// this method will always wait for at least fpMinWaitDuration and never longer
|
|
|
|
// than fpMaxWaitDuration. If s.loopStopped is closed, it will return false
|
|
|
|
// immediately. The estimation is based on the total number of fingerprints as
|
|
|
|
// passed in.
|
2014-11-10 13:26:07 -08:00
|
|
|
func (s *memorySeriesStorage) waitForNextFP(numberOfFPs int) bool {
|
2014-11-13 07:55:15 -08:00
|
|
|
d := fpMaxWaitDuration
|
2014-11-10 13:26:07 -08:00
|
|
|
if numberOfFPs != 0 {
|
2014-11-13 07:55:15 -08:00
|
|
|
sweepTime := s.purgeAfter / 10
|
|
|
|
if sweepTime > fpMaxSweepTime {
|
|
|
|
sweepTime = fpMaxSweepTime
|
|
|
|
}
|
|
|
|
d = sweepTime / time.Duration(numberOfFPs)
|
|
|
|
if d < fpMinWaitDuration {
|
|
|
|
d = fpMinWaitDuration
|
2014-11-10 13:26:07 -08:00
|
|
|
}
|
2014-11-13 07:55:15 -08:00
|
|
|
if d > fpMaxWaitDuration {
|
|
|
|
d = fpMaxWaitDuration
|
2014-11-10 13:26:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
t := time.NewTimer(d)
|
|
|
|
select {
|
|
|
|
case <-t.C:
|
|
|
|
return true
|
|
|
|
case <-s.loopStopping:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 12:03:51 -08:00
|
|
|
// cycleThroughMemoryFingerprints returns a channel that emits fingerprints for
|
|
|
|
// series in memory in a throttled fashion. It continues to cycle through all
|
|
|
|
// fingerprints in memory until s.loopStopping is closed.
|
|
|
|
func (s *memorySeriesStorage) cycleThroughMemoryFingerprints() chan clientmodel.Fingerprint {
|
2014-11-10 13:26:07 -08:00
|
|
|
memoryFingerprints := make(chan clientmodel.Fingerprint)
|
|
|
|
go func() {
|
|
|
|
var fpIter <-chan clientmodel.Fingerprint
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if fpIter != nil {
|
|
|
|
for _ = range fpIter {
|
|
|
|
// Consume the iterator.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(memoryFingerprints)
|
|
|
|
}()
|
|
|
|
|
|
|
|
for {
|
|
|
|
// Initial wait, also important if there are no FPs yet.
|
|
|
|
if !s.waitForNextFP(s.fpToSeries.length()) {
|
|
|
|
return
|
|
|
|
}
|
2014-11-20 12:03:51 -08:00
|
|
|
begin := time.Now()
|
2014-11-10 13:26:07 -08:00
|
|
|
fpIter = s.fpToSeries.fpIter()
|
|
|
|
for fp := range fpIter {
|
|
|
|
select {
|
|
|
|
case memoryFingerprints <- fp:
|
|
|
|
case <-s.loopStopping:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.waitForNextFP(s.fpToSeries.length())
|
|
|
|
}
|
2014-11-20 12:03:51 -08:00
|
|
|
glog.Infof("Completed maintenance sweep through in-memory fingerprints in %v.", time.Since(begin))
|
2014-11-10 13:26:07 -08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2014-11-20 12:03:51 -08:00
|
|
|
return memoryFingerprints
|
|
|
|
}
|
|
|
|
|
|
|
|
// cycleThroughArchivedFingerprints returns a channel that emits fingerprints
|
|
|
|
// for archived series in a throttled fashion. It continues to cycle through all
|
|
|
|
// archived fingerprints until s.loopStopping is closed.
|
|
|
|
func (s *memorySeriesStorage) cycleThroughArchivedFingerprints() chan clientmodel.Fingerprint {
|
2014-11-10 13:26:07 -08:00
|
|
|
archivedFingerprints := make(chan clientmodel.Fingerprint)
|
|
|
|
go func() {
|
|
|
|
defer close(archivedFingerprints)
|
|
|
|
|
|
|
|
for {
|
|
|
|
archivedFPs, err := s.persistence.getFingerprintsModifiedBefore(
|
|
|
|
clientmodel.TimestampFromTime(time.Now()).Add(-1 * s.purgeAfter),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
glog.Error("Failed to lookup archived fingerprint ranges: ", err)
|
|
|
|
s.waitForNextFP(0)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Initial wait, also important if there are no FPs yet.
|
|
|
|
if !s.waitForNextFP(len(archivedFPs)) {
|
|
|
|
return
|
|
|
|
}
|
2014-11-20 12:03:51 -08:00
|
|
|
begin := time.Now()
|
2014-11-10 13:26:07 -08:00
|
|
|
for _, fp := range archivedFPs {
|
|
|
|
select {
|
|
|
|
case archivedFingerprints <- fp:
|
|
|
|
case <-s.loopStopping:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.waitForNextFP(len(archivedFPs))
|
|
|
|
}
|
2014-11-20 12:03:51 -08:00
|
|
|
glog.Infof("Completed maintenance sweep through archived fingerprints in %v.", time.Since(begin))
|
2014-11-10 13:26:07 -08:00
|
|
|
}
|
|
|
|
}()
|
2014-11-20 12:03:51 -08:00
|
|
|
return archivedFingerprints
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *memorySeriesStorage) loop() {
|
|
|
|
checkpointTicker := time.NewTicker(s.checkpointInterval)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
checkpointTicker.Stop()
|
|
|
|
glog.Info("Maintenance loop stopped.")
|
|
|
|
close(s.loopStopped)
|
|
|
|
}()
|
|
|
|
|
|
|
|
memoryFingerprints := s.cycleThroughMemoryFingerprints()
|
|
|
|
archivedFingerprints := s.cycleThroughArchivedFingerprints()
|
2014-11-10 13:26:07 -08:00
|
|
|
|
|
|
|
loop:
|
2014-06-06 02:55:53 -07:00
|
|
|
for {
|
|
|
|
select {
|
2014-10-24 11:27:27 -07:00
|
|
|
case <-s.loopStopping:
|
2014-11-10 13:26:07 -08:00
|
|
|
break loop
|
2014-10-24 11:27:27 -07:00
|
|
|
case <-checkpointTicker.C:
|
2014-10-27 12:40:48 -07:00
|
|
|
s.persistence.checkpointSeriesMapAndHeads(s.fpToSeries, s.fpLocker)
|
2014-11-10 13:26:07 -08:00
|
|
|
case fp := <-memoryFingerprints:
|
|
|
|
s.purgeSeries(fp, clientmodel.TimestampFromTime(time.Now()).Add(-1*s.purgeAfter))
|
2014-11-13 11:50:25 -08:00
|
|
|
s.maintainSeries(fp)
|
2014-11-12 08:12:57 -08:00
|
|
|
s.seriesOps.WithLabelValues(memoryMaintenance).Inc()
|
2014-11-10 13:26:07 -08:00
|
|
|
case fp := <-archivedFingerprints:
|
|
|
|
s.purgeSeries(fp, clientmodel.TimestampFromTime(time.Now()).Add(-1*s.purgeAfter))
|
2014-11-12 08:12:57 -08:00
|
|
|
s.seriesOps.WithLabelValues(archiveMaintenance).Inc()
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
}
|
2014-11-10 13:26:07 -08:00
|
|
|
// Wait until both channels are closed.
|
2014-11-20 12:03:51 -08:00
|
|
|
for _ = range memoryFingerprints {
|
2014-11-10 13:26:07 -08:00
|
|
|
}
|
2014-11-20 12:03:51 -08:00
|
|
|
for _ = range archivedFingerprints {
|
2014-11-10 13:26:07 -08:00
|
|
|
}
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-13 11:50:25 -08:00
|
|
|
// maintainSeries closes the head chunk if not touched in a while. It archives a
|
|
|
|
// series if all chunks are evicted. It evicts chunkDescs if there are too many.
|
|
|
|
func (s *memorySeriesStorage) maintainSeries(fp clientmodel.Fingerprint) {
|
|
|
|
var headChunkToPersist *chunkDesc
|
|
|
|
s.fpLocker.Lock(fp)
|
|
|
|
defer func() {
|
|
|
|
s.fpLocker.Unlock(fp)
|
|
|
|
// Queue outside of lock!
|
|
|
|
if headChunkToPersist != nil {
|
|
|
|
s.persistQueue <- persistRequest{fp, headChunkToPersist}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
series, ok := s.fpToSeries.get(fp)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
iOldestNotEvicted := -1
|
|
|
|
for i, cd := range series.chunkDescs {
|
|
|
|
if !cd.isEvicted() {
|
|
|
|
iOldestNotEvicted = i
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Archive if all chunks are evicted.
|
|
|
|
if iOldestNotEvicted == -1 {
|
|
|
|
s.fpToSeries.del(fp)
|
|
|
|
s.numSeries.Dec()
|
|
|
|
if err := s.persistence.archiveMetric(
|
|
|
|
fp, series.metric, series.firstTime(), series.lastTime(),
|
|
|
|
); err != nil {
|
|
|
|
glog.Errorf("Error archiving metric %v: %v", series.metric, err)
|
|
|
|
} else {
|
|
|
|
s.seriesOps.WithLabelValues(archive).Inc()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// If we are here, the series is not archived, so check for chunkDesc
|
|
|
|
// eviction next and then if the head chunk needs to be persisted.
|
|
|
|
series.evictChunkDescs(iOldestNotEvicted)
|
|
|
|
if !series.headChunkPersisted && time.Now().Sub(series.head().firstTime().Time()) > headChunkTimeout {
|
|
|
|
series.headChunkPersisted = true
|
|
|
|
// Since we cannot modify the head chunk from now on, we
|
|
|
|
// don't need to bother with cloning anymore.
|
|
|
|
series.headChunkUsedByIterator = false
|
|
|
|
headChunkToPersist = series.head()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 09:22:08 -08:00
|
|
|
// purgeSeries purges chunks older than beforeTime from a series. If the series
|
|
|
|
// contains no chunks after the purge, it is dropped entirely.
|
2014-09-16 06:47:24 -07:00
|
|
|
func (s *memorySeriesStorage) purgeSeries(fp clientmodel.Fingerprint, beforeTime clientmodel.Timestamp) {
|
2014-10-07 10:11:24 -07:00
|
|
|
s.fpLocker.Lock(fp)
|
|
|
|
defer s.fpLocker.Unlock(fp)
|
2014-09-10 09:41:52 -07:00
|
|
|
|
2014-10-27 12:40:48 -07:00
|
|
|
if series, ok := s.fpToSeries.get(fp); ok {
|
2014-11-10 09:22:08 -08:00
|
|
|
// Deal with series in memory.
|
|
|
|
if !series.firstTime().Before(beforeTime) {
|
|
|
|
// Oldest sample not old enough.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newFirstTime, numDropped, allDropped, err := s.persistence.dropChunks(fp, beforeTime)
|
|
|
|
if err != nil {
|
|
|
|
glog.Error("Error purging persisted chunks: ", err)
|
|
|
|
}
|
2014-10-27 12:40:48 -07:00
|
|
|
numPurged, allPurged := series.purgeOlderThan(beforeTime)
|
|
|
|
if allPurged && allDropped {
|
|
|
|
s.fpToSeries.del(fp)
|
2014-10-23 06:18:32 -07:00
|
|
|
s.numSeries.Dec()
|
|
|
|
s.seriesOps.WithLabelValues(memoryPurge).Inc()
|
2014-10-28 11:01:41 -07:00
|
|
|
s.persistence.unindexMetric(fp, series.metric)
|
2014-10-27 12:40:48 -07:00
|
|
|
} else if series.chunkDescsOffset != -1 {
|
2014-11-10 09:22:08 -08:00
|
|
|
series.savedFirstTime = newFirstTime
|
2014-10-27 12:40:48 -07:00
|
|
|
series.chunkDescsOffset += numPurged - numDropped
|
|
|
|
if series.chunkDescsOffset < 0 {
|
|
|
|
panic("dropped more chunks from persistence than from memory")
|
|
|
|
}
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
2014-09-10 09:41:52 -07:00
|
|
|
return
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
2014-11-10 09:22:08 -08:00
|
|
|
// Deal with archived series.
|
|
|
|
has, firstTime, lastTime, err := s.persistence.hasArchivedMetric(fp)
|
|
|
|
if err != nil {
|
|
|
|
glog.Error("Error looking up archived time range: ", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !has || !firstTime.Before(beforeTime) {
|
|
|
|
// Oldest sample not old enough, or metric purged or unarchived in the meantime.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newFirstTime, _, allDropped, err := s.persistence.dropChunks(fp, beforeTime)
|
|
|
|
if err != nil {
|
|
|
|
glog.Error("Error purging persisted chunks: ", err)
|
|
|
|
}
|
2014-10-15 06:53:05 -07:00
|
|
|
if allDropped {
|
|
|
|
if err := s.persistence.dropArchivedMetric(fp); err != nil {
|
|
|
|
glog.Errorf("Error dropping archived metric for fingerprint %v: %v", fp, err)
|
2014-11-10 09:22:08 -08:00
|
|
|
return
|
2014-10-15 06:53:05 -07:00
|
|
|
}
|
2014-11-10 09:22:08 -08:00
|
|
|
s.seriesOps.WithLabelValues(archivePurge).Inc()
|
|
|
|
return
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
2014-11-10 09:22:08 -08:00
|
|
|
s.persistence.updateArchivedTimeRange(fp, newFirstTime, lastTime)
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-27 11:46:45 -08:00
|
|
|
// See persistence.loadChunks for detailed explanation.
|
|
|
|
func (s *memorySeriesStorage) loadChunks(fp clientmodel.Fingerprint, indexes []int, indexOffset int) ([]chunk, error) {
|
|
|
|
return s.persistence.loadChunks(fp, indexes, indexOffset)
|
|
|
|
}
|
|
|
|
|
|
|
|
// See persistence.loadChunkDescs for detailed explanation.
|
|
|
|
func (s *memorySeriesStorage) loadChunkDescs(fp clientmodel.Fingerprint, beforeTime clientmodel.Timestamp) ([]*chunkDesc, error) {
|
|
|
|
return s.persistence.loadChunkDescs(fp, beforeTime)
|
|
|
|
}
|
|
|
|
|
2014-10-23 06:18:32 -07:00
|
|
|
// To expose persistQueueCap as metric:
|
|
|
|
var (
|
|
|
|
persistQueueCapDesc = prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(namespace, subsystem, "persist_queue_capacity"),
|
|
|
|
"The total capacity of the persist queue.",
|
|
|
|
nil, nil,
|
|
|
|
)
|
|
|
|
persistQueueCapGauge = prometheus.MustNewConstMetric(
|
|
|
|
persistQueueCapDesc, prometheus.GaugeValue, persistQueueCap,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2014-10-07 10:11:24 -07:00
|
|
|
// Describe implements prometheus.Collector.
|
|
|
|
func (s *memorySeriesStorage) Describe(ch chan<- *prometheus.Desc) {
|
|
|
|
s.persistence.Describe(ch)
|
2014-10-23 06:18:32 -07:00
|
|
|
|
|
|
|
ch <- s.persistLatency.Desc()
|
|
|
|
s.persistErrors.Describe(ch)
|
|
|
|
ch <- s.persistQueueLength.Desc()
|
|
|
|
ch <- s.numSeries.Desc()
|
|
|
|
s.seriesOps.Describe(ch)
|
|
|
|
ch <- s.ingestedSamplesCount.Desc()
|
2014-11-05 11:02:45 -08:00
|
|
|
ch <- s.invalidPreloadRequestsCount.Desc()
|
2014-10-23 06:18:32 -07:00
|
|
|
|
|
|
|
ch <- persistQueueCapDesc
|
|
|
|
|
|
|
|
ch <- numMemChunksDesc
|
2014-10-07 10:11:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect implements prometheus.Collector.
|
|
|
|
func (s *memorySeriesStorage) Collect(ch chan<- prometheus.Metric) {
|
|
|
|
s.persistence.Collect(ch)
|
2014-10-23 06:18:32 -07:00
|
|
|
|
|
|
|
ch <- s.persistLatency
|
|
|
|
s.persistErrors.Collect(ch)
|
|
|
|
ch <- s.persistQueueLength
|
|
|
|
ch <- s.numSeries
|
|
|
|
s.seriesOps.Collect(ch)
|
|
|
|
ch <- s.ingestedSamplesCount
|
2014-11-05 11:02:45 -08:00
|
|
|
ch <- s.invalidPreloadRequestsCount
|
2014-10-23 06:18:32 -07:00
|
|
|
|
|
|
|
ch <- persistQueueCapGauge
|
|
|
|
|
|
|
|
count := atomic.LoadInt64(&numMemChunks)
|
|
|
|
ch <- prometheus.MustNewConstMetric(numMemChunksDesc, prometheus.GaugeValue, float64(count))
|
2014-10-07 10:11:24 -07:00
|
|
|
}
|