local

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2017 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package local contains the local time series storage used by Prometheus.

Index

Constants

View Source
const (
	// Version of the storage as it can be found in the version file.
	// Increment to protect against incompatible changes.
	Version = 1
)

Variables

View Source
var (
	// ErrOutOfOrderSample is returned if a sample has a timestamp before the latest
	// timestamp in the series it is appended to.
	ErrOutOfOrderSample = fmt.Errorf("sample timestamp out of order")
	// ErrDuplicateSampleForTimestamp is returned if a sample has the same
	// timestamp as the latest sample in the series it is appended to but a
	// different value. (Appending an identical sample is a no-op and does
	// not cause an error.)
	ErrDuplicateSampleForTimestamp = fmt.Errorf("sample with repeated timestamp but different value")
)

Functions

func DumpHeads

func DumpHeads(filename string, out io.Writer) error

DumpHeads writes the metadata of the provided heads file in a human-readable form.

Types

type MemorySeriesStorage

type MemorySeriesStorage struct {
	// contains filtered or unexported fields
}

A MemorySeriesStorage manages series in memory over time, while also interfacing with a persistence layer to make time series data persistent across restarts and evictable from memory.

func NewMemorySeriesStorage

func NewMemorySeriesStorage(o *MemorySeriesStorageOptions) *MemorySeriesStorage

NewMemorySeriesStorage returns a newly allocated Storage. Storage.Serve still has to be called to start the storage.

func NewTestStorage

func NewTestStorage(t testutil.T, encoding chunk.Encoding) (*MemorySeriesStorage, testutil.Closer)

NewTestStorage creates a storage instance backed by files in a temporary directory. The returned storage is already in serving state. Upon closing the returned test.Closer, the temporary directory is cleaned up.

func (*MemorySeriesStorage) Append

func (s *MemorySeriesStorage) Append(sample *model.Sample) error

Append implements Storage.

func (*MemorySeriesStorage) Collect

func (s *MemorySeriesStorage) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*MemorySeriesStorage) Describe

func (s *MemorySeriesStorage) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*MemorySeriesStorage) DropMetricsForLabelMatchers added in v1.1.0

func (s *MemorySeriesStorage) DropMetricsForLabelMatchers(_ context.Context, matchers ...*metric.LabelMatcher) (int, error)

DropMetricsForLabelMatchers implements Storage.

func (*MemorySeriesStorage) LabelValuesForLabelName

func (s *MemorySeriesStorage) LabelValuesForLabelName(_ context.Context, labelName model.LabelName) (model.LabelValues, error)

LabelValuesForLabelName implements Storage.

func (*MemorySeriesStorage) LastSampleForLabelMatchers added in v1.1.0

func (s *MemorySeriesStorage) LastSampleForLabelMatchers(_ context.Context, cutoff model.Time, matcherSets ...metric.LabelMatchers) (model.Vector, error)

LastSampleForLabelMatchers implements Storage.

func (*MemorySeriesStorage) MetricsForLabelMatchers

func (s *MemorySeriesStorage) MetricsForLabelMatchers(
	_ context.Context,
	from, through model.Time,
	matcherSets ...metric.LabelMatchers,
) ([]metric.Metric, error)

MetricsForLabelMatchers implements Storage.

func (*MemorySeriesStorage) NeedsThrottling

func (s *MemorySeriesStorage) NeedsThrottling() bool

NeedsThrottling implements Storage.

func (*MemorySeriesStorage) Querier added in v1.3.0

func (s *MemorySeriesStorage) Querier() (Querier, error)

Querier implements the storage interface.

func (*MemorySeriesStorage) QueryInstant added in v1.1.0

func (s *MemorySeriesStorage) QueryInstant(ctx context.Context, ts model.Time, stalenessDelta time.Duration, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error)

QueryInstant implements Storage.

func (*MemorySeriesStorage) QueryRange added in v1.1.0

func (s *MemorySeriesStorage) QueryRange(ctx context.Context, from, through model.Time, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error)

QueryRange implements Storage.

func (*MemorySeriesStorage) Start

func (s *MemorySeriesStorage) Start() (err error)

Start implements Storage.

func (*MemorySeriesStorage) Stop

func (s *MemorySeriesStorage) Stop() error

Stop implements Storage.

func (*MemorySeriesStorage) WaitForIndexing

func (s *MemorySeriesStorage) WaitForIndexing()

WaitForIndexing implements Storage.

type MemorySeriesStorageOptions

type MemorySeriesStorageOptions struct {
	TargetHeapSize             uint64        // Desired maximum heap size.
	PersistenceStoragePath     string        // Location of persistence files.
	PersistenceRetentionPeriod time.Duration // Chunks at least that old are dropped.
	HeadChunkTimeout           time.Duration // Head chunks idle for at least that long may be closed.
	CheckpointInterval         time.Duration // How often to checkpoint the series map and head chunks.
	CheckpointDirtySeriesLimit int           // How many dirty series will trigger an early checkpoint.
	Dirty                      bool          // Force the storage to consider itself dirty on startup.
	PedanticChecks             bool          // If dirty, perform crash-recovery checks on each series file.
	SyncStrategy               SyncStrategy  // Which sync strategy to apply to series files.
	MinShrinkRatio             float64       // Minimum ratio a series file has to shrink during truncation.
	NumMutexes                 int           // Number of mutexes used for stochastic fingerprint locking.
}

MemorySeriesStorageOptions contains options needed by NewMemorySeriesStorage. It is not safe to leave any of those at their zero values.

type NoopQuerier added in v1.3.0

type NoopQuerier struct{}

NoopQuerier is a dummy Querier for use when Prometheus's local storage is disabled. It is returned by the NoopStorage Querier method and always returns empty results.

func (*NoopQuerier) Close added in v1.3.0

func (s *NoopQuerier) Close() error

Close implements Querier.

func (*NoopQuerier) LabelValuesForLabelName added in v1.3.0

func (s *NoopQuerier) LabelValuesForLabelName(ctx context.Context, labelName model.LabelName) (model.LabelValues, error)

LabelValuesForLabelName implements Querier.

func (*NoopQuerier) LastSampleForLabelMatchers added in v1.3.0

func (s *NoopQuerier) LastSampleForLabelMatchers(ctx context.Context, cutoff model.Time, matcherSets ...metric.LabelMatchers) (model.Vector, error)

LastSampleForLabelMatchers implements Querier.

func (*NoopQuerier) MetricsForLabelMatchers added in v1.3.0

func (s *NoopQuerier) MetricsForLabelMatchers(
	ctx context.Context,
	from, through model.Time,
	matcherSets ...metric.LabelMatchers,
) ([]metric.Metric, error)

MetricsForLabelMatchers implements Querier.

func (*NoopQuerier) QueryInstant added in v1.3.0

func (s *NoopQuerier) QueryInstant(ctx context.Context, ts model.Time, stalenessDelta time.Duration, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error)

QueryInstant implements Querier.

func (*NoopQuerier) QueryRange added in v1.3.0

func (s *NoopQuerier) QueryRange(ctx context.Context, from, through model.Time, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error)

QueryRange implements Querier

type NoopStorage added in v1.2.0

type NoopStorage struct{}

NoopStorage is a dummy storage for use when Prometheus's local storage is disabled. It throws away any appended samples and returns empty results.

func (*NoopStorage) Append added in v1.2.0

func (s *NoopStorage) Append(sample *model.Sample) error

Append implements Storage.

func (*NoopStorage) DropMetricsForLabelMatchers added in v1.2.0

func (s *NoopStorage) DropMetricsForLabelMatchers(ctx context.Context, matchers ...*metric.LabelMatcher) (int, error)

DropMetricsForLabelMatchers implements Storage.

func (*NoopStorage) NeedsThrottling added in v1.2.0

func (s *NoopStorage) NeedsThrottling() bool

NeedsThrottling implements Storage.

func (*NoopStorage) Querier added in v1.3.0

func (s *NoopStorage) Querier() (Querier, error)

Querier implements Storage.

func (*NoopStorage) Start added in v1.2.0

func (s *NoopStorage) Start() (err error)

Start implements Storage.

func (*NoopStorage) Stop added in v1.2.0

func (s *NoopStorage) Stop() error

Stop implements Storage.

func (*NoopStorage) WaitForIndexing added in v1.2.0

func (s *NoopStorage) WaitForIndexing()

WaitForIndexing implements Storage.

type Querier

type Querier interface {
	// Close closes the querier. Behavior for subsequent calls to Querier methods
	// is undefined.
	Close() error
	// QueryRange returns a list of series iterators for the selected
	// time range and label matchers. The iterators need to be closed
	// after usage.
	QueryRange(ctx context.Context, from, through model.Time, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error)
	// QueryInstant returns a list of series iterators for the selected
	// instant and label matchers. The iterators need to be closed after usage.
	QueryInstant(ctx context.Context, ts model.Time, stalenessDelta time.Duration, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error)
	// MetricsForLabelMatchers returns the metrics from storage that satisfy
	// the given sets of label matchers. Each set of matchers must contain at
	// least one label matcher that does not match the empty string. Otherwise,
	// an empty list is returned. Within one set of matchers, the intersection
	// of matching series is computed. The final return value will be the union
	// of the per-set results. The times from and through are hints for the
	// storage to optimize the search. The storage MAY exclude metrics that
	// have no samples in the specified interval from the returned map. In
	// doubt, specify model.Earliest for from and model.Latest for through.
	MetricsForLabelMatchers(ctx context.Context, from, through model.Time, matcherSets ...metric.LabelMatchers) ([]metric.Metric, error)
	// LastSampleForLabelMatchers returns the last samples that have been
	// ingested for the time series matching the given set of label matchers.
	// The label matching behavior is the same as in MetricsForLabelMatchers.
	// All returned samples are between the specified cutoff time and now.
	LastSampleForLabelMatchers(ctx context.Context, cutoff model.Time, matcherSets ...metric.LabelMatchers) (model.Vector, error)
	// Get all of the label values that are associated with a given label name.
	LabelValuesForLabelName(context.Context, model.LabelName) (model.LabelValues, error)
}

Querier allows querying a time series storage.

type SeriesIterator

type SeriesIterator interface {
	// Gets the value that is closest before the given time. In case a value
	// exists at precisely the given time, that value is returned. If no
	// applicable value exists, model.ZeroSamplePair is returned.
	ValueAtOrBeforeTime(model.Time) model.SamplePair
	// Gets all values contained within a given interval.
	RangeValues(metric.Interval) []model.SamplePair
	// Returns the metric of the series that the iterator corresponds to.
	Metric() metric.Metric
	// Closes the iterator and releases the underlying data.
	Close()
}

SeriesIterator enables efficient access of sample values in a series. Its methods are not goroutine-safe. A SeriesIterator iterates over a snapshot of a series, i.e. it is safe to continue using a SeriesIterator after or during modifying the corresponding series, but the iterator will represent the state of the series prior to the modification.

type Storage

type Storage interface {
	// Querier returns a new Querier on the storage.
	Querier() (Querier, error)

	// This SampleAppender needs multiple samples for the same fingerprint to be
	// submitted in chronological order, from oldest to newest. When Append has
	// returned, the appended sample might not be queryable immediately. (Use
	// WaitForIndexing to wait for complete processing.) The implementation might
	// remove labels with empty value from the provided Sample as those labels
	// are considered equivalent to a label not present at all.
	//
	// Appending is throttled if the Storage has too many chunks in memory
	// already or has too many chunks waiting for persistence.
	storage.SampleAppender

	// Drop all time series associated with the given label matchers. Returns
	// the number series that were dropped.
	DropMetricsForLabelMatchers(context.Context, ...*metric.LabelMatcher) (int, error)
	// Run the various maintenance loops in goroutines. Returns when the
	// storage is ready to use. Keeps everything running in the background
	// until Stop is called.
	Start() error
	// Stop shuts down the Storage gracefully, flushes all pending
	// operations, stops all maintenance loops,and frees all resources.
	Stop() error
	// WaitForIndexing returns once all samples in the storage are
	// indexed. Indexing is needed for FingerprintsForLabelMatchers and
	// LabelValuesForLabelName and may lag behind.
	WaitForIndexing()
}

Storage ingests and manages samples, along with various indexes. All methods are goroutine-safe. Storage implements storage.SampleAppender.

type SyncStrategy

type SyncStrategy int

SyncStrategy is an enum to select a sync strategy for series files.

const (
	Never SyncStrategy
	Always
	Adaptive
)

Possible values for SyncStrategy.

func (*SyncStrategy) Set

func (ss *SyncStrategy) Set(s string) error

Set implements flag.Value.

func (SyncStrategy) String

func (ss SyncStrategy) String() string

String implements flag.Value.

Directories

Path Synopsis
Package codable provides types that implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler and functions that help to encode and decode primitives.
Package codable provides types that implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler and functions that help to encode and decode primitives.
Package index provides a number of indexes backed by persistent key-value stores.
Package index provides a number of indexes backed by persistent key-value stores.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL