Documentation ¶
Overview ¶
Package model contains core representation of Prometheus client primitives.
Index ¶
- Constants
- Variables
- func LabelsToSignature(labels map[string]string) uint64
- func SignatureForLabels(m Metric, labels LabelNames) uint64
- func SignatureWithoutLabels(m Metric, labels map[LabelName]struct{}) uint64
- type COWMetric
- type Fingerprint
- type FingerprintSet
- type Fingerprints
- type LabelName
- type LabelNames
- type LabelSet
- type LabelValue
- type LabelValues
- type Metric
- func (m Metric) Before(o Metric) bool
- func (m Metric) Clone() Metric
- func (m Metric) Equal(o Metric) bool
- func (m Metric) FastFingerprint() Fingerprint
- func (m Metric) Fingerprint() Fingerprint
- func (m Metric) MergeFromLabelSet(labels LabelSet, collisionPrefix LabelName)
- func (m Metric) String() string
- type Sample
- type SampleValue
- type Samples
- type Timestamp
- func (t Timestamp) Add(d native_time.Duration) Timestamp
- func (t Timestamp) After(o Timestamp) bool
- func (t Timestamp) Before(o Timestamp) bool
- func (t Timestamp) Equal(o Timestamp) bool
- func (t Timestamp) MarshalJSON() ([]byte, error)
- func (t Timestamp) String() string
- func (t Timestamp) Sub(o Timestamp) native_time.Duration
- func (t Timestamp) Time() native_time.Time
- func (t Timestamp) Unix() int64
- func (t Timestamp) UnixNano() int64
Constants ¶
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" )
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) )
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 ¶
var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
LabelNameRE is a regular expression matching valid label names.
Functions ¶
func LabelsToSignature ¶
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 ¶
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 ¶
COWMetric wraps a Metric to enable copy-on-write access patterns.
func (*COWMetric) Delete ¶
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 ¶
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.
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) Less ¶
func (f Fingerprints) Less(i, j int) bool
Less 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 ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*LabelName) UnmarshalYAML ¶
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) MergeFromMetric ¶
MergeFromMetric merges Metric into this LabelSet.
func (*LabelSet) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
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 ¶
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) 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 ¶
MergeFromLabelSet merges a label set into this Metric, prefixing a collision prefix to the label names merged from the label set where required.
type Sample ¶
type Sample struct { Metric Metric Value SampleValue Timestamp Timestamp }
Sample is a sample value with a timestamp and a metric.
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.
type Timestamp ¶
type Timestamp int64
Timestamp is the number of milliseconds since the epoch (1970-01-01 00:00 UTC) excluding leap seconds.
func TimestampFromTime ¶
func TimestampFromTime(t native_time.Time) Timestamp
TimestampFromTime returns the Timestamp equivalent to the time.Time t.
func TimestampFromUnix ¶
TimestampFromUnix returns the Timestamp equivalent to the Unix timestamp t provided in seconds.
func TimestampFromUnixNano ¶
TimestampFromUnixNano returns the Timestamp equivalent to the Unix timestamp t provided in nanoseconds.
func (Timestamp) Add ¶
func (t Timestamp) Add(d native_time.Duration) Timestamp
Add returns the Timestamp t + d.
func (Timestamp) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Timestamp) Sub ¶
func (t Timestamp) Sub(o Timestamp) native_time.Duration
Sub returns the Duration t - o.
func (Timestamp) Time ¶
func (t Timestamp) Time() native_time.Time
Time returns the time.Time representation of t.