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.
go get github.com/b0ch3nski/go-prom-remote-write@latest
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)