prometheus

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	HTTPClientTimeout: defaulHTTPClientTimeout,
	UserAgent:         defaultUserAgent,
}

DefaultConfig represents the default configuration used to construct a client.

Functions

This section is empty.

Types

type Client

type Client interface {
	// WriteProto writes the Prom proto WriteRequest to the specified endpoint.
	WriteProto(
		ctx context.Context,
		req *prompb.WriteRequest,
		opts WriteOptions,
	) (WriteResult, WriteError)

	// WriteTimeSeries converts the []TimeSeries to Protobuf then writes it to the specified endpoint.
	WriteTimeSeries(
		ctx context.Context,
		ts TSList,
		opts WriteOptions,
	) (WriteResult, WriteError)
}

Client is used to write timeseries data to a Prom remote write endpoint

func NewClient

func NewClient(c Config) (Client, error)

NewClient creates a new remote write coordinator client.

type Config

type Config struct {
	// WriteURL is the URL which the client uses to write to prometheus.
	WriteURL string `yaml:"writeURL"`

	//HTTPClientTimeout is the timeout that is set for the client.
	HTTPClientTimeout time.Duration `yaml:"httpClientTimeout"`

	// If not nil, http client is used instead of constructing one.
	HTTPClient *http.Client

	// UserAgent is the `User-Agent` header in the request.
	UserAgent string `yaml:"userAgent"`
}

Config defines the configuration used to construct a client.

func NewConfig

func NewConfig(opts ...ConfigOption) Config

NewConfig creates a new Config struct based on options passed to the function.

type ConfigOption

type ConfigOption func(*Config)

ConfigOption defines a config option that can be used when constructing a client.

func HTTPClientOption

func HTTPClientOption(httpClient *http.Client) ConfigOption

HTTPClientOption sets the HTTP client that is set for the client.

func HTTPClientTimeoutOption

func HTTPClientTimeoutOption(httpClientTimeout time.Duration) ConfigOption

HTTPClientTimeoutOption sets the timeout that is set for the client.

func UserAgent

func UserAgent(userAgent string) ConfigOption

UserAgent sets the `User-Agent` header in the request.

func WriteURLOption

func WriteURLOption(writeURL string) ConfigOption

WriteURLOption sets the URL which the client uses to write to prometheus.

type Datapoint

type Datapoint struct {
	Timestamp time.Time
	Value     float64
}

A Datapoint is a single data value reported at a given time.

type Label

type Label struct {
	Name  string
	Value string
}

Label is a metric label.

type TSList

type TSList []TimeSeries

TSList is a slice of TimeSeries.

type TimeSeries

type TimeSeries struct {
	Labels    []Label
	Datapoint Datapoint
}

TimeSeries are made of labels and a datapoint.

type WriteError

type WriteError interface {
	error
	StatusCode() int
}

WriteError is an error that can also return the HTTP status code if the response is what caused an error.

type WriteOptions

type WriteOptions struct {
	// Headers to append or override the outgoing headers.
	Headers map[string]string
}

WriteOptions specifies additional write options.

type WriteResult

type WriteResult struct {
	StatusCode  int
	PayloadSize int
}

WriteResult returns the successful HTTP status code.

Jump to

Keyboard shortcuts

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