prometheus

package
v2.13.15 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const AcceptHeader = `text/plain`

AcceptHeader starting with ksm 1.5 only plain text encoding is supported

View Source
const EmptyValue noValueType = "no_value"

EmptyValue means we could not get the value.

Variables

View Source
var ControlPlaneComponentTypeGenerator = func(
	groupLabel string,
	_ string,
	_ definition.RawGroups,
	clusterName string,
) (string, error) {
	return fmt.Sprintf("k8s:%s:controlplane:%s", clusterName, groupLabel), nil
}

ControlPlaneComponentTypeGenerator generates the entity type of a control plane component.

View Source
var FromRawEntityIDGenerator = func(_, rawEntityID string, _ definition.RawGroups) (string, error) {
	return rawEntityID, nil
}

FromRawEntityIDGenerator generates the entity type of a control plane component.

Functions

func FromLabelValue

func FromLabelValue(key, label string) definition.FetchFunc

FromLabelValue creates a FetchFunc that fetches values from prometheus metrics labels.

func FromLabelValueEntityIDGenerator

func FromLabelValueEntityIDGenerator(key, label string) definition.EntityIDGeneratorFunc

FromLabelValueEntityIDGenerator generates an entityID using the value of the specified label for the given metric key.

func FromLabelValueEntityTypeGenerator

func FromLabelValueEntityTypeGenerator(key string) definition.EntityTypeGeneratorFunc

FromLabelValueEntityTypeGenerator generates the entity type using the cluster name and group label. If group label is different than "namespace" or "node", then entity type is also composed of namespace. If group label is "container" then pod name is also included.

func FromLabelsValueEntityIDGeneratorForPendingPods

func FromLabelsValueEntityIDGeneratorForPendingPods() definition.EntityIDGeneratorFunc

FromLabelsValueEntityIDGeneratorForPendingPods generates entity ID for a pod in pending status, which is not scheduled. Otherwise entity ID is not generated. This is due to the fact that Kubelet /pods endpoint does not have information about those pods. The rest of the pods is reported from Kubelet /pods endpoint.

func FromSummary

func FromSummary(key string) definition.FetchFunc

FromSummary creates a FetchFunc that fetches values from prometheus histogram.

It will create one attribute for the count, one for the sum and one per quantile. The attributes names will be generated by suffixing the time-series labels to the given key, and by suffixing and identifier for type of the time-series in relation to the summary (count, sum or quantile).

- <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_sum - <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_count - <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_quantile_<quantile_dimention_1> - ... - <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_quantile_<quantile_dimention_n>

Since it expects the RawValue to be of type []Metric it should be used when grouping with GroupEntityMetricsBySpec.

func FromValue

func FromValue(metricName string, labelsFilter ...LabelsFilter) definition.FetchFunc

FromValue creates a FetchFunc that fetches values from prometheus metrics values.

func FromValueWithOverriddenName

func FromValueWithOverriddenName(metricName string, nameOverride string, labelsFilter ...LabelsFilter) definition.FetchFunc

FromValueWithOverriddenName creates a FetchFunc that fetches values from prometheus metrics values. If there are multiple values returned, and nameOverride is not empty, this name will be used as a prefix instead of the metricName.

func GroupEntityMetricsBySpec

func GroupEntityMetricsBySpec(
	specs definition.SpecGroups,
	families []MetricFamily,
	rawEntityID string,
) (g definition.RawGroups, errs []error)

GroupEntityMetricsBySpec groups metrics coming from Prometheus by the given rawEntityID and metric spec.

It differs from GroupMetricsBySpec in that the key that maps to the RawMetrics is always the given rawEntityID and that the RawValues are of the form []Metric instead of Metric.

Using the given rawEntityID as the entity key for the metrics is useful in cases when all the []MetricFamily belong to the same entity and there is no way to infer that from the metrics. A good example is querying the metrics endpoint of a control plane component.

The resulting RawGroups are of the form:

{
  groupLabel: {
    rawEntityID: {
      metric_name: [ Metric1, Metric2, ..., Metricn ]
    }
  }
}

func GroupMetricsBySpec

func GroupMetricsBySpec(specs definition.SpecGroups, families []MetricFamily) (g definition.RawGroups, errs []error)

GroupMetricsBySpec groups metrics coming from Prometheus by a given metric spec. Example: grouping by K8s pod, container, etc.

func IgnoreLabelsFilter

func IgnoreLabelsFilter(labelsToIgnore ...string) func(Labels) Labels

IgnoreLabelsFilter returns a function that filters-out the given labels.

func IncludeOnlyLabelsFilter

func IncludeOnlyLabelsFilter(labelsToInclude ...string) func(Labels) Labels

IncludeOnlyLabelsFilter returns a function that filters-out all but the given labels.

func InheritAllLabelsFrom

func InheritAllLabelsFrom(parentGroupLabel, relatedMetricKey string) definition.FetchFunc

InheritAllLabelsFrom gets all the label values from from a related metric. Related metric means any metric you can get with the info that you have in your own metric.

func InheritAllSelectorsFrom

func InheritAllSelectorsFrom(parentGroupLabel, relatedMetricKey string) definition.FetchFunc

InheritAllSelectorsFrom gets all the label values from from a related metric and changes the prefix "selector_" for "selector.". It's meant to be used with metrics that contain label selectors. Related metric means any metric you can get with the info that you have in your own metric.

func InheritSpecificLabelValuesFrom

func InheritSpecificLabelValuesFrom(parentGroupLabel, relatedMetricKey string, labelsToRetrieve map[string]string) definition.FetchFunc

InheritSpecificLabelValuesFrom gets the specified label values from a related metric. Related metric means any metric you can get with the info that you have in your own metric.

func NewRequest

func NewRequest(method, url string) (*http.Request, error)

NewRequest returns a new Request given a method, URL, setting the required header for accepting protobuf.

Types

type CounterValue

type CounterValue float64

CounterValue represents the value of a counter type metric.

func (CounterValue) String

func (v CounterValue) String() string

String implements the Stringer interface method.

type GaugeValue

type GaugeValue float64

GaugeValue represents the value of a gauge type metric.

func (GaugeValue) String

func (v GaugeValue) String() string

String implements the Stringer interface method.

type Labels

type Labels map[string]string

Labels is a map containing the label pair of a metric.

func (Labels) AreIn

func (l Labels) AreIn(p []*model.LabelPair) bool

AreIn says if the labels are included in to the provided Prometheus label pair.

func (Labels) Has

func (l Labels) Has(name string) bool

Has checks if the label exists.

type LabelsFilter

type LabelsFilter func(Labels) Labels

LabelsFilter are functions used to filter labels when executing some definition.FetchFunc.

type Metric

type Metric struct {
	Labels Labels
	Value  Value
}

Metric is for all "single value" metrics, i.e. Counter, Gauge, and Untyped.

type MetricFamily

type MetricFamily struct {
	Name    string
	Type    string
	Metrics []Metric
}

MetricFamily is an aggregation of metrics with same name.

func Do

func Do(c client.HTTPClient, endpoint string, queries []Query) ([]MetricFamily, error)

Do is the main entry point. It runs queries against the Prometheus metrics provided by the endpoint.

func (*MetricFamily) Valid

func (f *MetricFamily) Valid() bool

Valid validates that all the attributes were filled.

type Query

type Query struct {
	CustomName string
	MetricName string
	Labels     QueryLabels
	Value      QueryValue // TODO Only supported Counter and Gauge
}

Query represents the query object. It will run against Prometheus metrics.

func (Query) Execute

func (q Query) Execute(promMetricFamily *model.MetricFamily) (metricFamily MetricFamily)

Execute runs the query.

type QueryLabels

type QueryLabels struct {
	Operator QueryOperator
	Labels   Labels
}

QueryLabels represents the query for labels.

type QueryOperator

type QueryOperator int

QueryOperator indicates the operator used for the query.

const (
	// QueryOpAnd Is the default operator. Means all values should match.
	QueryOpAnd QueryOperator = iota

	// QueryOpNor means all values should not match.
	QueryOpNor
)

type QueryValue

type QueryValue struct {
	Operator QueryOperator
	Value    Value
}

QueryValue represents the query for a value.

type Value

type Value interface {
	fmt.Stringer
}

Value is the value of a metric.

Jump to

Keyboard shortcuts

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