Skip to content

b0ch3nski/go-prom-remote-write

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 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

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)
}