metricclient

package
v0.0.0-...-f67e10c Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0, MIT Imports: 22 Imported by: 0

Documentation

Overview

Package metricclient provides utility functions to start, stop, and talk to a metric server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricClient

type MetricClient struct {
	// contains filtered or unexported fields
}

MetricClient implements an HTTP client that can spawn and connect to a running runsc metrics server process and register/unregister sandbox metrics.

func NewMetricClient

func NewMetricClient(addr, rootDir string) *MetricClient

NewMetricClient creates a new MetricClient that can talk to the metric server at address addr.

func (*MetricClient) Close

func (c *MetricClient) Close()

Close closes any idle HTTP connection.

func (*MetricClient) GetMetrics

func (c *MetricClient) GetMetrics(ctx context.Context, urlParams map[string]string) (MetricData, error)

GetMetrics returns the raw Prometheus-formatted metric data from the metric server. `urlParams` may contain a special parameter with the empty string as the key. If this is set, that string is used to override the request path from its default value of `/metrics`.

func (*MetricClient) HealthCheck

func (c *MetricClient) HealthCheck(ctx context.Context) error

HealthCheck pokes the metrics server and checks that it is running.

func (*MetricClient) ShutdownServer

func (c *MetricClient) ShutdownServer(ctx context.Context) error

ShutdownServer asks the metrics server to shut itself down. It blocks until the server process has exitted or the context expires.

func (*MetricClient) SpawnServer

func (c *MetricClient) SpawnServer(ctx context.Context, baseConf *config.Config, extraArgs ...string) error

SpawnServer starts a metric server at the expected address. It blocks until it responds to healthchecks, or the context expires. Fails if the server fails to start or to bind within the context. Callers should call ShutdownServer to stop the server. A running server must be stopped before a new one can be successfully started. baseConf is used for passing other flags to the server, e.g. debug log directory.

type MetricData

type MetricData string

MetricData is the raw contents returned by GetMetrics, with helper functions to extract single values out of it.

func (MetricData) GetPrometheusContainerInteger

func (m MetricData) GetPrometheusContainerInteger(want WantMetric) (int64, time.Time, error)

GetPrometheusContainerInteger returns the integer value of a Prometheus metric from the given WantMetric data.

func (MetricData) GetPrometheusInteger

func (m MetricData) GetPrometheusInteger(metricName string, wantLabels map[string]string) (int64, time.Time, error)

GetPrometheusInteger returns the integer value of a Prometheus metric with given name and labels.

func (MetricData) GetSandboxMetadataMetric

func (m MetricData) GetSandboxMetadataMetric(want WantMetric) (map[string]string, error)

GetSandboxMetadataMetric returns the labels attached to the metadata metric for a given sandbox.

type WantMetric

type WantMetric struct {
	// Metric is the name of the metric to get.
	Metric string
	// Sandbox is the ID of the sandbox to look up the metric for.
	Sandbox string
	// Pod and Namespace are the pod and namespace labels associated with the sandbox.
	// Leave empty if the sandbox metadata doesn't contain this information.
	Pod, Namespace string
	// ExtraLabels are additional key-value labels that must match.
	ExtraLabels map[string]string
}

WantMetric designates the metadata required to select a single metric from a single sandbox.

Jump to

Keyboard shortcuts

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