go-prom-remote-write

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0

README

go-prom-remote-write

go.dev goreportcard sourcegraph

Bare minimum Prometheus Remote-Write client, based on Proto files acquired from upstream repository.
All dependencies were cut down with only snappy and protobuf remaining.
Data marshaling doesn't use reflection, thanks to the vtprotobuf generation helper.

For a code generation procedure, see included Makefile.

Simple client fulfills the Remote-Write specification with couple small additions, like ability to handle timeouts and Basic authentication.

install

go get github.com/b0ch3nski/go-prom-remote-write

example

promClient := client.
	NewClient("http://localhost:9090/api/v1/write").
	WithAuthBasic("username", "password").
	WithTimeout(3 * time.Second).
	WithHttpClient(&http.Client{Transport: &http.Transport{MaxConnsPerHost: 0}})

series := []*model.TimeSeries{
	{
		Samples: []*model.Sample{
			{
				Value:     321.123,
				Timestamp: time.Now().UTC().UnixMilli(),
			},
		},
		Labels: []*model.Label{
			{
				Name:  "__name__",
				Value: "test_metric",
			},
		},
	},
}

if err := promClient.Write(context.Background(), series); err != nil {
	panic(err)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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