Package model
Overview ▹
Index ▹
Constants
const ( // AlertNameLabel is the name of the label containing the an alert's name. AlertNameLabel = "alertname" // ExportedLabelPrefix is the prefix to prepend to the label names present in // exported metrics if a label of the same name is added by the server. ExportedLabelPrefix = "exported_" // MetricNameLabel is the label name indicating the metric name of a // timeseries. MetricNameLabel = "__name__" // SchemeLabel is the name of the label that holds the scheme on which to // scrape a target. SchemeLabel = "__scheme__" // AddressLabel is the name of the label that holds the address of // a scrape target. AddressLabel = "__address__" // MetricsPathLabel is the name of the label that holds the path on which to // scrape a target. MetricsPathLabel = "__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_" // TmpLabelPrefix is a prefix for temporary labels as part of relabelling. // Labels with this prefix are used for intermediate label processing and // will not be attached to time series. This is reserved for use in // Prometheus configuration files by users. TmpLabelPrefix = "__tmp_" // ParamLabelPrefix is a prefix for labels that provide URL parameters // used to scrape a target. ParamLabelPrefix = "__param_" // JobLabel is the label name indicating the job from which a timeseries // was scraped. JobLabel = "job" // InstanceLabel is the label name used for the instance label. InstanceLabel = "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 ( // Earliest is the earliest Time representable. Handy for // initializing a high watermark. Earliest = Time(math.MinInt64) // Latest is the latest Time representable. Handy for initializing // a low watermark. Latest = Time(math.MaxInt64) )
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).
const SeparatorByte byte = 255
Variables
var ( // ZeroSamplePair is the pseudo zero-value of SamplePair used to signal a // non-existing sample pair. It is a SamplePair with timestamp Earliest and // value 0.0. Note that the natural zero value of SamplePair has a timestamp // of 0, which is possible to appear in a real SamplePair and thus not // suitable to signal a non-existing SamplePair. ZeroSamplePair = SamplePair{Timestamp: Earliest} // ZeroSample is the pseudo zero-value of Sample used to signal a // non-existing sample. It is a Sample with timestamp Earliest, value 0.0, // and metric nil. Note that the natural zero value of Sample has a timestamp // of 0, which is possible to appear in a real Sample and thus not suitable // to signal a non-existing Sample. ZeroSample = Sample{Timestamp: Earliest} )
LabelNameRE is a regular expression matching valid label names. Note that the IsValid method of LabelName performs the same check but faster than a match with this regular expression.
var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
var ( // MetricNameRE is a regular expression matching valid metric // names. Note that the IsValidMetricName function performs the same // check but faster than a match with this regular expression. MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`) )
func IsValidMetricName ¶
func IsValidMetricName(n LabelValue) bool
IsValidMetricName returns true iff name matches the pattern of MetricNameRE. This function, however, does not use MetricNameRE for the check but a much faster hardcoded implementation.
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 ...LabelName) 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.
type Alert ¶
Alert is a generic representation of an alert in the Prometheus eco-system.
type Alert struct { // Label value pairs for purpose of aggregation, matching, and disposition // dispatching. This must minimally include an "alertname" label. Labels LabelSet `json:"labels"` // Extra key/value information which does not define alert identity. Annotations LabelSet `json:"annotations"` // The known time range for this alert. Both ends are optional. StartsAt time.Time `json:"startsAt,omitempty"` EndsAt time.Time `json:"endsAt,omitempty"` GeneratorURL string `json:"generatorURL"` }
func (*Alert) Fingerprint ¶
func (a *Alert) Fingerprint() Fingerprint
Fingerprint returns a unique hash for the alert. It is equivalent to the fingerprint of the alert's label set.
func (*Alert) Name ¶
func (a *Alert) Name() string
Name returns the name of the alert. It is equivalent to the "alertname" label.
func (*Alert) Resolved ¶
func (a *Alert) Resolved() bool
Resolved returns true iff the activity interval ended in the past.
func (*Alert) ResolvedAt ¶
func (a *Alert) ResolvedAt(ts time.Time) bool
ResolvedAt returns true off the activity interval ended before the given timestamp.
func (*Alert) Status ¶
func (a *Alert) Status() AlertStatus
Status returns the status of the alert.
func (*Alert) String ¶
func (a *Alert) String() string
func (*Alert) Validate ¶
func (a *Alert) Validate() error
Validate checks whether the alert data is inconsistent.
type AlertStatus ¶
type AlertStatus string
const ( AlertFiring AlertStatus = "firing" AlertResolved AlertStatus = "resolved" )
type Alerts ¶
Alert is a list of alerts that can be sorted in chronological order.
type Alerts []*Alert
func (Alerts) HasFiring ¶
func (as Alerts) HasFiring() bool
HasFiring returns true iff one of the alerts is not resolved.
func (Alerts) Len ¶
func (as Alerts) Len() int
func (Alerts) Less ¶
func (as Alerts) Less(i, j int) bool
func (Alerts) Status ¶
func (as Alerts) Status() AlertStatus
Status returns StatusFiring iff at least one of the alerts is firing.
func (Alerts) Swap ¶
func (as Alerts) Swap(i, j int)
type Duration ¶
Duration wraps time.Duration. It is used to parse the custom duration format from YAML. This type should not propagate beyond the scope of input/output processing.
type Duration time.Duration
func ParseDuration ¶
func ParseDuration(durationStr string) (Duration, error)
ParseDuration parses a string into a time.Duration, assuming that a year always has 365d, a week always has 7d, and a day always has 24h.
func (Duration) MarshalYAML ¶
func (d Duration) MarshalYAML() (interface{}, error)
MarshalYAML implements the yaml.Marshaler interface.
func (*Duration) Set ¶
func (d *Duration) Set(s string) error
Set implements pflag/flag.Value
func (Duration) String ¶
func (d Duration) String() string
func (*Duration) Type ¶
func (d *Duration) Type() string
Type implements pflag.Value
func (*Duration) UnmarshalYAML ¶
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface.
type Fingerprint ¶
Fingerprint provides a hash-capable representation of a Metric. For our purposes, FNV-1A 64-bit is used.
type Fingerprint uint64
func FingerprintFromString ¶
func FingerprintFromString(s string) (Fingerprint, error)
FingerprintFromString transforms a string representation into a Fingerprint.
func ParseFingerprint ¶
func ParseFingerprint(s string) (Fingerprint, error)
ParseFingerprint parses the input string into a fingerprint.
func (Fingerprint) String ¶
func (f Fingerprint) String() string
type FingerprintSet ¶
FingerprintSet is a set of Fingerprints.
type FingerprintSet map[Fingerprint]struct{}
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 ¶
Fingerprints represents a collection of Fingerprint subject to a given natural sorting scheme. It implements sort.Interface.
type Fingerprints []Fingerprint
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 Interval ¶
Interval describes and interval between two timestamps.
type Interval struct { Start, End Time }
type LabelName ¶
A LabelName is a key for a LabelSet or Metric. It has a value associated therewith.
type LabelName string
func (LabelName) IsValid ¶
func (ln LabelName) IsValid() bool
IsValid is true iff the label name matches the pattern of LabelNameRE. This method, however, does not use LabelNameRE for the check but a much faster hardcoded implementation.
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 ¶
LabelNames is a sortable LabelName slice. In implements sort.Interface.
type LabelNames []LabelName
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 LabelPair ¶
LabelPair pairs a name with a value.
type LabelPair struct { Name LabelName Value LabelValue }
type LabelPairs ¶
LabelPairs is a sortable slice of LabelPair pointers. It implements sort.Interface.
type LabelPairs []*LabelPair
func (LabelPairs) Len ¶
func (l LabelPairs) Len() int
func (LabelPairs) Less ¶
func (l LabelPairs) Less(i, j int) bool
func (LabelPairs) Swap ¶
func (l LabelPairs) Swap(i, j int)
type LabelSet ¶
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.
type LabelSet map[LabelName]LabelValue
func (LabelSet) Before ¶
func (ls LabelSet) Before(o LabelSet) 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 (LabelSet) Clone ¶
func (ls LabelSet) Clone() LabelSet
Clone returns a copy of the label set.
func (LabelSet) Equal ¶
func (ls LabelSet) Equal(o LabelSet) bool
Equal returns true iff both label sets have exactly the same key/value pairs.
func (LabelSet) FastFingerprint ¶
func (ls LabelSet) FastFingerprint() Fingerprint
FastFingerprint returns the LabelSet's Fingerprint calculated by a faster hashing algorithm, which is, however, more susceptible to hash collisions.
func (LabelSet) Fingerprint ¶
func (ls LabelSet) Fingerprint() Fingerprint
Fingerprint returns the LabelSet's fingerprint.
func (LabelSet) Merge ¶
func (l LabelSet) Merge(other LabelSet) LabelSet
Merge is a helper function to non-destructively merge two label sets.
func (LabelSet) String ¶
func (l LabelSet) String() string
func (*LabelSet) UnmarshalJSON ¶
func (l *LabelSet) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (LabelSet) Validate ¶
func (ls LabelSet) Validate() error
Validate checks whether all names and values in the label set are valid.
type LabelValue ¶
A LabelValue is an associated value for a LabelName.
type LabelValue string
func (LabelValue) IsValid ¶
func (lv LabelValue) IsValid() bool
IsValid returns true iff the string is a valid UTF8.
type LabelValues ¶
LabelValues is a sortable LabelValue slice. It implements sort.Interface.
type LabelValues []LabelValue
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 Matcher ¶
Matcher describes a matches the value of a given label.
type Matcher struct { Name LabelName `json:"name"` Value string `json:"value"` IsRegex bool `json:"isRegex"` }
func (*Matcher) UnmarshalJSON ¶
func (m *Matcher) UnmarshalJSON(b []byte) error
func (*Matcher) Validate ¶
func (m *Matcher) Validate() error
Validate returns true iff all fields of the matcher have valid values.
type Matrix ¶
Matrix is a list of time series.
type Matrix []*SampleStream
func (Matrix) Len ¶
func (m Matrix) Len() int
func (Matrix) Less ¶
func (m Matrix) Less(i, j int) bool
func (Matrix) String ¶
func (mat Matrix) String() string
func (Matrix) Swap ¶
func (m Matrix) Swap(i, j int)
func (Matrix) Type ¶
func (Matrix) Type() ValueType
type Metric ¶
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.
type Metric LabelSet
func (Metric) Before ¶
func (m Metric) Before(o Metric) bool
Before compares the metrics' underlying label sets.
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) String ¶
func (m Metric) String() string
type Sample ¶
Sample is a sample pair associated with a metric.
type Sample struct { Metric Metric `json:"metric"` Value SampleValue `json:"value"` Timestamp Time `json:"timestamp"` }
func (*Sample) Equal ¶
func (s *Sample) Equal(o *Sample) bool
Equal compares first the metrics, then the timestamp, then the value. The sematics of value equality is defined by SampleValue.Equal.
func (Sample) MarshalJSON ¶
func (s Sample) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (Sample) String ¶
func (s Sample) String() string
func (*Sample) UnmarshalJSON ¶
func (s *Sample) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type SamplePair ¶
SamplePair pairs a SampleValue with a Timestamp.
type SamplePair struct { Timestamp Time Value SampleValue }
func (*SamplePair) Equal ¶
func (s *SamplePair) Equal(o *SamplePair) bool
Equal returns true if this SamplePair and o have equal Values and equal Timestamps. The sematics of Value equality is defined by SampleValue.Equal.
func (SamplePair) MarshalJSON ¶
func (s SamplePair) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (SamplePair) String ¶
func (s SamplePair) String() string
func (*SamplePair) UnmarshalJSON ¶
func (s *SamplePair) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type SampleStream ¶
SampleStream is a stream of Values belonging to an attached COWMetric.
type SampleStream struct { Metric Metric `json:"metric"` Values []SamplePair `json:"values"` }
func (SampleStream) String ¶
func (ss SampleStream) String() string
type SampleValue ¶
A SampleValue is a representation of a value for a given sample at a given time.
type SampleValue float64
func (SampleValue) Equal ¶
func (v SampleValue) Equal(o SampleValue) bool
Equal returns true if the value of v and o is equal or if both are NaN. Note that v==o is false if both are NaN. If you want the conventional float behavior, use == to compare two SampleValues.
func (SampleValue) MarshalJSON ¶
func (v SampleValue) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (SampleValue) String ¶
func (v SampleValue) String() string
func (*SampleValue) UnmarshalJSON ¶
func (v *SampleValue) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Samples ¶
Samples is a sortable Sample slice. It implements sort.Interface.
type Samples []*Sample
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 Scalar ¶
Scalar is a scalar value evaluated at the set timestamp.
type Scalar struct { Value SampleValue `json:"value"` Timestamp Time `json:"timestamp"` }
func (Scalar) MarshalJSON ¶
func (s Scalar) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (Scalar) String ¶
func (s Scalar) String() string
func (*Scalar) Type ¶
func (*Scalar) Type() ValueType
func (*Scalar) UnmarshalJSON ¶
func (s *Scalar) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Silence ¶
Silence defines the representation of a silence definiton in the Prometheus eco-system.
type Silence struct { ID uint64 `json:"id,omitempty"` Matchers []*Matcher `json:"matchers"` StartsAt time.Time `json:"startsAt"` EndsAt time.Time `json:"endsAt"` CreatedAt time.Time `json:"createdAt,omitempty"` CreatedBy string `json:"createdBy"` Comment string `json:"comment,omitempty"` }
func (*Silence) Validate ¶
func (s *Silence) Validate() error
Validate returns true iff all fields of the silence have valid values.
type String ¶
String is a string value evaluated at the set timestamp.
type String struct { Value string `json:"value"` Timestamp Time `json:"timestamp"` }
func (String) MarshalJSON ¶
func (s String) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*String) String ¶
func (s *String) String() string
func (*String) Type ¶
func (*String) Type() ValueType
func (*String) UnmarshalJSON ¶
func (s *String) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Time ¶
Time is the number of milliseconds since the epoch (1970-01-01 00:00 UTC) excluding leap seconds.
type Time int64
func Now ¶
func Now() Time
Now returns the current time as a Time.
func TimeFromUnix ¶
func TimeFromUnix(t int64) Time
TimeFromUnix returns the Time equivalent to the Unix Time t provided in seconds.
func TimeFromUnixNano ¶
func TimeFromUnixNano(t int64) Time
TimeFromUnixNano returns the Time equivalent to the Unix Time t provided in nanoseconds.
func (Time) Add ¶
func (t Time) Add(d time.Duration) Time
Add returns the Time t + d.
func (Time) After ¶
func (t Time) After(o Time) bool
After reports whether the Time t is after o.
func (Time) Before ¶
func (t Time) Before(o Time) bool
Before reports whether the Time t is before o.
func (Time) Equal ¶
func (t Time) Equal(o Time) bool
Equal reports whether two Times represent the same instant.
func (Time) MarshalJSON ¶
func (t Time) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (Time) String ¶
func (t Time) String() string
String returns a string representation of the Time.
func (Time) Sub ¶
func (t Time) Sub(o Time) time.Duration
Sub returns the Duration t - o.
func (Time) Time ¶
func (t Time) Time() time.Time
Time returns the time.Time representation of t.
func (Time) Unix ¶
func (t Time) Unix() int64
Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.
func (Time) UnixNano ¶
func (t Time) UnixNano() int64
UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC.
func (*Time) UnmarshalJSON ¶
func (t *Time) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type Value ¶
Value is a generic interface for values resulting from a query evaluation.
type Value interface { Type() ValueType String() string }
type ValueType ¶
type ValueType int
const ( ValNone ValueType = iota ValScalar ValVector ValMatrix ValString )
func (ValueType) MarshalJSON ¶
func (et ValueType) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (ValueType) String ¶
func (e ValueType) String() string
func (*ValueType) UnmarshalJSON ¶
func (et *ValueType) UnmarshalJSON(b []byte) error
type Vector ¶
Vector is basically only an alias for Samples, but the contract is that in a Vector, all Samples have the same timestamp.
type Vector []*Sample
func (Vector) Equal ¶
func (vec Vector) Equal(o Vector) bool
Equal compares two sets of samples and returns true if they are equal.
func (Vector) Len ¶
func (vec Vector) Len() int
func (Vector) Less ¶
func (vec Vector) Less(i, j int) bool
Less compares first the metrics, then the timestamp.
func (Vector) String ¶
func (vec Vector) String() string
func (Vector) Swap ¶
func (vec Vector) Swap(i, j int)
func (Vector) Type ¶
func (Vector) Type() ValueType