Skip to content

Bare minimum Prometheus Remote-Write client.

License

Notifications You must be signed in to change notification settings

b0ch3nski/go-prom-remote-write

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-prom-remote-write

license release go.dev goreportcard issues 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@latest

example

import "github.com/b0ch3nski/go-prom-remote-write/promrw"
import "github.com/b0ch3nski/go-prom-remote-write/promrw/model"

promClient := promrw.
	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",
			},
		},
	},
}

promClient.Write(context.Background(), series)