promwrite

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 9 Imported by: 10

README

promwrite

Prometheus Remote Write Go client with minimal dependencies. Supports Prometheus, Cortex, VictoriaMetrics etc.

Install
go get github.com/castai/promwrite
Example Usage
client := promwrite.NewClient("http://prometheus:8428/api/v1/write")
resp, err := client.Write(context.Background(), &promwrite.WriteRequest{
	TimeSeries: []promwrite.TimeSeries{
		{
			Labels: []promwrite.Label{
				{
					Name:  "__name__",
					Value: "my_metric_name",
				},
			},
			Sample: promwrite.Sample{
				Time:  time.Now(),
				Value: 123,
			},
		},
	},
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is Prometheus Remote Write client.

func NewClient

func NewClient(endpoint string, options ...ClientOption) *Client

func (*Client) Write

func (p *Client) Write(ctx context.Context, req *WriteRequest, options ...WriteOption) (*WriteResponse, error)

Write sends HTTP requests to Prometheus Remote Write compatible API endpoint including Prometheus, Cortex and VictoriaMetrics.

func (*Client) WriteProto added in v0.6.0

func (p *Client) WriteProto(ctx context.Context, req *prompb.WriteRequest, options ...WriteOption) (*WriteResponse, error)

WriteProto sends HTTP requests to Prometheus Remote Write compatible API endpoint including Prometheus, Cortex and VictoriaMetrics. The difference between Write and WriteProto is that WriteProto allows you to write the full prompb.WriteRequest, which supports all metrics.

type ClientOption

type ClientOption func(opts *clientOptions)

ClientOption is used to set custom client options.

func HttpClient

func HttpClient(client *http.Client) ClientOption

HttpClient option allows configuring custom HTTP client.

type Label

type Label struct {
	Name  string
	Value string
}

type Sample

type Sample struct {
	Time  time.Time
	Value float64
}

type TimeSeries

type TimeSeries struct {
	Labels []Label
	Sample Sample
}

type WriteError

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

WriteError returned if HTTP call is finished with response status code, but it was not successful.

func (*WriteError) Error

func (e *WriteError) Error() string

func (*WriteError) StatusCode

func (e *WriteError) StatusCode() int

type WriteOption

type WriteOption func(opts *writeOptions)

func WriteHeaders

func WriteHeaders(headers map[string]string) WriteOption

WriteHeaders allows passing custom HTTP headers. Once common use case is to pass `X-Scope-OrgID` header for Cortex tenant.

type WriteRequest

type WriteRequest struct {
	TimeSeries []TimeSeries
}

type WriteResponse

type WriteResponse struct {
}

Jump to

Keyboard shortcuts

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