model

package
Version: v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package model contains core representation of Prometheus client primitives.

Index

Constants

View Source
const (
	// ExporterLabelPrefix is the label name prefix to prepend if a
	// synthetic label is already present in the exported metrics.
	ExporterLabelPrefix LabelName = "exporter_"

	// MetricNameLabel is the label name indicating the metric name of a
	// timeseries.
	MetricNameLabel LabelName = "__name__"

	// AddressLabel is the name of the label that holds the address of
	// a scrape target.
	AddressLabel LabelName = "__address__"

	// MetricsPathLabel is the name of the label that holds the path on which to
	// scrape a target.
	MetricsPathLabel LabelName = "__metrics_path__"

	// ReservedLabelPrefix is a prefix which is not legal in user-supplied
	// label names.
	ReservedLabelPrefix = "__"

	// MetaLabelPrefix is a prefix for labels that provide meta information.
	// Labels with this prefix are used for intermediate label processing and
	// will not be attached to time series.
	MetaLabelPrefix = "__meta_"

	// JobLabel is the label name indicating the job from which a timeseries
	// was scraped.
	JobLabel LabelName = "job"

	// InstanceLabel is the label name used for the instance label.
	InstanceLabel LabelName = "instance"

	// BucketLabel is used for the label that defines the upper bound of a
	// bucket of a histogram ("le" -> "less or equal").
	BucketLabel = "le"

	// QuantileLabel is used for the label that defines the quantile in a
	// summary.
	QuantileLabel = "quantile"
)
View Source
const (
	// MinimumTick is the minimum supported time resolution. This has to be
	// at least native_time.Second in order for the code below to work.
	MinimumTick = native_time.Millisecond

	// Earliest is the earliest timestamp representable. Handy for
	// initializing a high watermark.
	Earliest = Timestamp(math.MinInt64)
	// Latest is the latest timestamp representable. Handy for initializing
	// a low watermark.
	Latest = Timestamp(math.MaxInt64)
)
View Source
const SeparatorByte byte = 255

SeparatorByte is a byte that cannot occur in valid UTF-8 sequences and is used to separate label names, label values, and other strings from each other when calculating their combined hash value (aka signature aka fingerprint).

Variables

View Source
var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")

LabelNameRE is a regular expression matching valid label names.

Functions

func LabelsToSignature

func LabelsToSignature(labels map[string]string) uint64

LabelsToSignature returns a quasi-unique signature (i.e., fingerprint) for a given label set. (Collisions are possible but unlikely if the number of label sets the function is applied to is small.)

func SignatureForLabels

func SignatureForLabels(m Metric, labels LabelNames) uint64

SignatureForLabels works like LabelsToSignature but takes a Metric as parameter (rather than a label map) and only includes the labels with the specified LabelNames into the signature calculation. The labels passed in will be sorted by this function.

func SignatureWithoutLabels

func SignatureWithoutLabels(m Metric, labels map[LabelName]struct{}) uint64

SignatureWithoutLabels works like LabelsToSignature but takes a Metric as parameter (rather than a label map) and excludes the labels with any of the specified LabelNames from the signature calculation.

Types

type COWMetric

type COWMetric struct {
	Copied bool
	Metric Metric
}

COWMetric wraps a Metric to enable copy-on-write access patterns.

func (*COWMetric) Delete

func (m *COWMetric) Delete(ln LabelName)

Delete deletes a given label name from the wrapped Metric and copies the Metric initially, if it is not already a copy.

func (COWMetric) MarshalJSON

func (m COWMetric) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*COWMetric) Set

func (m *COWMetric) Set(ln LabelName, lv LabelValue)

Set sets a label name in the wrapped Metric to a given value and copies the Metric initially, if it is not already a copy.

func (COWMetric) String

func (m COWMetric) String() string

String implements fmt.Stringer.

type Fingerprint

type Fingerprint uint64

Fingerprint provides a hash-capable representation of a Metric. For our purposes, FNV-1A 64-bit is used.

func (Fingerprint) Equal

func (f Fingerprint) Equal(o Fingerprint) bool

Equal implements sort.Interface.

func (Fingerprint) Less

func (f Fingerprint) Less(o Fingerprint) bool

Less implements sort.Interface.

func (*Fingerprint) LoadFromString

func (f *Fingerprint) LoadFromString(s string) error

LoadFromString transforms a string representation into a Fingerprint.

func (Fingerprint) String

func (f Fingerprint) String() string

type FingerprintSet

type FingerprintSet map[Fingerprint]struct{}

FingerprintSet is a set of Fingerprints.

func (FingerprintSet) Equal

func (s FingerprintSet) Equal(o FingerprintSet) bool

Equal returns true if both sets contain the same elements (and not more).

func (FingerprintSet) Intersection

func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet

Intersection returns the elements contained in both sets.

type Fingerprints

type Fingerprints []Fingerprint

Fingerprints represents a collection of Fingerprint subject to a given natural sorting scheme. It implements sort.Interface.

func (Fingerprints) Len

func (f Fingerprints) Len() int

Len implements sort.Interface.

func (Fingerprints) Less

func (f Fingerprints) Less(i, j int) bool

Less implements sort.Interface.

func (Fingerprints) Swap

func (f Fingerprints) Swap(i, j int)

Swap implements sort.Interface.

type LabelName

type LabelName string

A LabelName is a key for a LabelSet or Metric. It has a value associated therewith.

func (*LabelName) UnmarshalJSON

func (ln *LabelName) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*LabelName) UnmarshalYAML

func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type LabelNames

type LabelNames []LabelName

LabelNames is a sortable LabelName slice. In implements sort.Interface.

func (LabelNames) Len

func (l LabelNames) Len() int

func (LabelNames) Less

func (l LabelNames) Less(i, j int) bool

func (LabelNames) String

func (l LabelNames) String() string

func (LabelNames) Swap

func (l LabelNames) Swap(i, j int)

type LabelSet

type LabelSet map[LabelName]LabelValue

A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet may be fully-qualified down to the point where it may resolve to a single Metric in the data store or not. All operations that occur within the realm of a LabelSet can emit a vector of Metric entities to which the LabelSet may match.

func (LabelSet) Merge

func (l LabelSet) Merge(other LabelSet) LabelSet

Merge is a helper function to non-destructively merge two label sets.

func (LabelSet) MergeFromMetric

func (l LabelSet) MergeFromMetric(m Metric)

MergeFromMetric merges Metric into this LabelSet.

func (LabelSet) String

func (l LabelSet) String() string

func (*LabelSet) UnmarshalJSON

func (l *LabelSet) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type LabelValue

type LabelValue string

A LabelValue is an associated value for a LabelName.

type LabelValues

type LabelValues []LabelValue

LabelValues is a sortable LabelValue slice. It implements sort.Interface.

func (LabelValues) Len

func (l LabelValues) Len() int

func (LabelValues) Less

func (l LabelValues) Less(i, j int) bool

func (LabelValues) Swap

func (l LabelValues) Swap(i, j int)

type Metric

type Metric map[LabelName]LabelValue

A Metric is similar to a LabelSet, but the key difference is that a Metric is a singleton and refers to one and only one stream of samples.

func (Metric) Before

func (m Metric) Before(o Metric) bool

Before compares the metrics, using the following criteria:

If m has fewer labels than o, it is before o. If it has more, it is not.

If the number of labels is the same, the superset of all label names is sorted alphanumerically. The first differing label pair found in that order determines the outcome: If the label does not exist at all in m, then m is before o, and vice versa. Otherwise the label value is compared alphanumerically.

If m and o are equal, the method returns false.

func (Metric) Clone

func (m Metric) Clone() Metric

Clone returns a copy of the Metric.

func (Metric) Equal

func (m Metric) Equal(o Metric) bool

Equal compares the metrics.

func (Metric) FastFingerprint

func (m Metric) FastFingerprint() Fingerprint

FastFingerprint returns a Metric's Fingerprint calculated by a faster hashing algorithm, which is, however, more susceptible to hash collisions.

func (Metric) Fingerprint

func (m Metric) Fingerprint() Fingerprint

Fingerprint returns a Metric's Fingerprint.

func (Metric) MergeFromLabelSet

func (m Metric) MergeFromLabelSet(labels LabelSet, collisionPrefix LabelName)

MergeFromLabelSet merges a label set into this Metric, prefixing a collision prefix to the label names merged from the label set where required.

func (Metric) String

func (m Metric) String() string

String implements Stringer.

type Sample

type Sample struct {
	Metric    Metric
	Value     SampleValue
	Timestamp Timestamp
}

Sample is a sample value with a timestamp and a metric.

func (*Sample) Equal

func (s *Sample) Equal(o *Sample) bool

Equal compares first the metrics, then the timestamp, then the value.

type SampleValue

type SampleValue float64

A SampleValue is a representation of a value for a given sample at a given time.

func (SampleValue) Equal

func (v SampleValue) Equal(o SampleValue) bool

Equal does a straight v==o.

func (SampleValue) MarshalJSON

func (v SampleValue) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (SampleValue) String

func (v SampleValue) String() string

type Samples

type Samples []*Sample

Samples is a sortable Sample slice. It implements sort.Interface.

func (Samples) Equal

func (s Samples) Equal(o Samples) bool

Equal compares two sets of samples and returns true if they are equal.

func (Samples) Len

func (s Samples) Len() int

func (Samples) Less

func (s Samples) Less(i, j int) bool

Less compares first the metrics, then the timestamp.

func (Samples) Swap

func (s Samples) Swap(i, j int)

type Timestamp

type Timestamp int64

Timestamp is the number of milliseconds since the epoch (1970-01-01 00:00 UTC) excluding leap seconds.

func Now

func Now() Timestamp

Now returns the current time as a Timestamp.

func TimestampFromTime

func TimestampFromTime(t native_time.Time) Timestamp

TimestampFromTime returns the Timestamp equivalent to the time.Time t.

func TimestampFromUnix

func TimestampFromUnix(t int64) Timestamp

TimestampFromUnix returns the Timestamp equivalent to the Unix timestamp t provided in seconds.

func TimestampFromUnixNano

func TimestampFromUnixNano(t int64) Timestamp

TimestampFromUnixNano returns the Timestamp equivalent to the Unix timestamp t provided in nanoseconds.

func (Timestamp) Add

Add returns the Timestamp t + d.

func (Timestamp) After

func (t Timestamp) After(o Timestamp) bool

After reports whether the timestamp t is after o.

func (Timestamp) Before

func (t Timestamp) Before(o Timestamp) bool

Before reports whether the timestamp t is before o.

func (Timestamp) Equal

func (t Timestamp) Equal(o Timestamp) bool

Equal reports whether two timestamps represent the same instant.

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Timestamp) String

func (t Timestamp) String() string

String returns a string representation of the timestamp.

func (Timestamp) Sub

Sub returns the Duration t - o.

func (Timestamp) Time

func (t Timestamp) Time() native_time.Time

Time returns the time.Time representation of t.

func (Timestamp) Unix

func (t Timestamp) Unix() int64

Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.

func (Timestamp) UnixNano

func (t Timestamp) UnixNano() int64

UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC.

Jump to

Keyboard shortcuts

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