prometheus

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: Apache-2.0 Imports: 16 Imported by: 81

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeLabelName added in v1.31.0

func SanitizeLabelName(name string) string

SanitizeLabelName replaces anything that doesn't match invalidLabelCharRE with an underscore. Copied from https://github.com/prometheus/prometheus/blob/df80dc4d3970121f2f76cba79050983ffb3cdbb0/util/strutil/strconv.go

Types

type Client

type Client struct {
	ClientInterface
	// contains filtered or unexported fields
}

Client for Prometheus API. It hides the way we query Prometheus offering a layer with a high level defined API.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new client to the Prometheus API. It returns an error on any problem.

func NewClientForConfig added in v1.27.0

func NewClientForConfig(cfg config.PrometheusConfig) (*Client, error)

NewClient creates a new client to the Prometheus API. It returns an error on any problem.

func (*Client) API

func (in *Client) API() prom_v1.API

API returns the Prometheus V1 HTTP API for performing calls not supported natively by this client

func (*Client) Address

func (in *Client) Address() string

Address return the configured Prometheus service URL

func (*Client) FetchHistogramRange added in v0.12.0

func (in *Client) FetchHistogramRange(metricName, labels, grouping string, q *RangeQuery) Histogram

FetchHistogramRange fetches bucketed metric as histogram in given range

func (*Client) FetchHistogramValues added in v1.27.0

func (in *Client) FetchHistogramValues(metricName, labels, grouping, rateInterval string, avg bool, quantiles []string, queryTime time.Time) (map[string]model.Vector, error)

FetchHistogramValues fetches bucketed metric as histogram at a given specific time

func (*Client) FetchRange added in v0.14.0

func (in *Client) FetchRange(metricName, labels, grouping, aggregator string, q *RangeQuery) Metric

FetchRange fetches a simple metric (gauge or counter) in given range

func (*Client) FetchRateRange added in v0.12.0

func (in *Client) FetchRateRange(metricName string, labels []string, grouping string, q *RangeQuery) Metric

FetchRateRange fetches a counter's rate in given range

func (*Client) GetAllRequestRates added in v0.6.0

func (in *Client) GetAllRequestRates(namespace string, ratesInterval string, queryTime time.Time) (model.Vector, error)

GetAllRequestRates queries Prometheus to fetch request counter rates, over a time interval, for requests into, internal to, or out of the namespace. Note that it does not discriminate on "reporter", so rates can be inflated due to duplication, and therefore should be used mainly for calculating ratios (e.g total rates / error rates). Returns (rates, error)

func (*Client) GetAppRequestRates added in v0.6.0

func (in *Client) GetAppRequestRates(namespace, app, ratesInterval string, queryTime time.Time) (model.Vector, model.Vector, error)

GetAppRequestRates queries Prometheus to fetch request counters rates over a time interval for a given app, both in and out. Note that it does not discriminate on "reporter", so rates can be inflated due to duplication, and therefore should be used mainly for calculating ratios (e.g total rates / error rates). Returns (in, out, error)

func (*Client) GetConfiguration added in v0.15.0

func (in *Client) GetConfiguration() (prom_v1.ConfigResult, error)

func (*Client) GetContext added in v1.29.0

func (in *Client) GetContext() context.Context

func (*Client) GetFlags added in v0.15.0

func (in *Client) GetFlags() (prom_v1.FlagsResult, error)

func (*Client) GetMetricsForLabels added in v0.17.0

func (in *Client) GetMetricsForLabels(labels []string) ([]string, error)

GetMetricsForLabels returns a list of metrics existing for the provided labels set

func (*Client) GetNamespaceServicesRequestRates

func (in *Client) GetNamespaceServicesRequestRates(namespace string, ratesInterval string, queryTime time.Time) (model.Vector, error)

GetNamespaceServicesRequestRates queries Prometheus to fetch request counter rates, over a time interval, limited to requests for services in the namespace. Note that it does not discriminate on "reporter", so rates can be inflated due to duplication, and therefore should be used mainly for calculating ratios (e.g total rates / error rates). Returns (rates, error)

func (*Client) GetServiceRequestRates

func (in *Client) GetServiceRequestRates(namespace, service, ratesInterval string, queryTime time.Time) (model.Vector, error)

GetServiceRequestRates queries Prometheus to fetch request counters rates over a time interval for a given service (hence only inbound). Note that it does not discriminate on "reporter", so rates can be inflated due to duplication, and therefore should be used mainly for calculating ratios (e.g total rates / error rates). Returns (in, error)

func (*Client) GetWorkloadRequestRates added in v0.6.0

func (in *Client) GetWorkloadRequestRates(namespace, workload, ratesInterval string, queryTime time.Time) (model.Vector, model.Vector, error)

GetWorkloadRequestRates queries Prometheus to fetch request counters rates over a time interval for a given workload, both in and out. Note that it does not discriminate on "reporter", so rates can be inflated due to duplication, and therefore should be used mainly for calculating ratios (e.g total rates / error rates). Returns (in, out, error)

func (*Client) Inject

func (in *Client) Inject(api prom_v1.API)

Inject allows for replacing the API with a mock For testing

type ClientInterface

type ClientInterface interface {
	FetchHistogramRange(metricName, labels, grouping string, q *RangeQuery) Histogram
	FetchHistogramValues(metricName, labels, grouping, rateInterval string, avg bool, quantiles []string, queryTime time.Time) (map[string]model.Vector, error)
	FetchRange(metricName, labels, grouping, aggregator string, q *RangeQuery) Metric
	FetchRateRange(metricName string, labels []string, grouping string, q *RangeQuery) Metric
	GetAllRequestRates(namespace, ratesInterval string, queryTime time.Time) (model.Vector, error)
	GetAppRequestRates(namespace, app, ratesInterval string, queryTime time.Time) (model.Vector, model.Vector, error)
	GetConfiguration() (prom_v1.ConfigResult, error)
	GetFlags() (prom_v1.FlagsResult, error)
	GetNamespaceServicesRequestRates(namespace, ratesInterval string, queryTime time.Time) (model.Vector, error)
	GetServiceRequestRates(namespace, service, ratesInterval string, queryTime time.Time) (model.Vector, error)
	GetWorkloadRequestRates(namespace, workload, ratesInterval string, queryTime time.Time) (model.Vector, model.Vector, error)
	GetMetricsForLabels(labels []string) ([]string, error)
}

ClientInterface for mocks (only mocked function are necessary here)

type Histogram

type Histogram = map[string]Metric

Histogram contains Metric objects for several histogram-kind statistics

type Metric

type Metric struct {
	Matrix model.Matrix `json:"matrix"`
	Err    error        `json:"-"`
}

Metric holds the Prometheus Matrix model, which contains one or more time series (depending on grouping)

type Metrics

type Metrics struct {
	Metrics    map[string]*Metric   `json:"metrics"`
	Histograms map[string]Histogram `json:"histograms"`
}

Metrics contains all simple metrics and histograms data

type PromCache added in v1.26.0

type PromCache interface {
	GetAllRequestRates(namespace string, ratesInterval string, queryTime time.Time) (bool, model.Vector)
	GetAppRequestRates(namespace, app, ratesInterval string, queryTime time.Time) (bool, model.Vector, model.Vector)
	GetNamespaceServicesRequestRates(namespace string, ratesInterval string, queryTime time.Time) (bool, model.Vector)
	GetServiceRequestRates(namespace, service, ratesInterval string, queryTime time.Time) (bool, model.Vector)
	GetWorkloadRequestRates(namespace, workload, ratesInterval string, queryTime time.Time) (bool, model.Vector, model.Vector)
	SetAllRequestRates(namespace string, ratesInterval string, queryTime time.Time, inResult model.Vector)
	SetAppRequestRates(namespace, app, ratesInterval string, queryTime time.Time, inResult model.Vector, outResult model.Vector)
	SetNamespaceServicesRequestRates(namespace string, ratesInterval string, queryTime time.Time, inResult model.Vector)
	SetServiceRequestRates(namespace, service, ratesInterval string, queryTime time.Time, inResult model.Vector)
	SetWorkloadRequestRates(namespace, workload, ratesInterval string, queryTime time.Time, inResult model.Vector, outResult model.Vector)
}

func NewPromCache added in v1.26.0

func NewPromCache() PromCache

type RangeQuery added in v1.27.0

type RangeQuery struct {
	prom_v1.Range
	RateInterval string
	RateFunc     string
	Quantiles    []string
	Avg          bool
	ByLabels     []string
}

RangeQuery holds common parameters for all kinds of range queries

func (*RangeQuery) FillDefaults added in v1.27.0

func (q *RangeQuery) FillDefaults()

FillDefaults fills the struct with default parameters

Directories

Path Synopsis
Package internalmetrics provides functionality to collect Prometheus metrics.
Package internalmetrics provides functionality to collect Prometheus metrics.

Jump to

Keyboard shortcuts

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