"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/prompb"
http.HandleFunc("/receive", func(w http.ResponseWriter, r *http.Request) {
compressed, err := ioutil.ReadAll(r.Body)
http.Error(w, err.Error(), http.StatusInternalServerError)
reqBuf, err := snappy.Decode(nil, compressed)
http.Error(w, err.Error(), http.StatusBadRequest)
var req prompb.WriteRequest
if err := proto.Unmarshal(reqBuf, &req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
for _, ts := range req.Timeseries {
m := make(model.Metric, len(ts.Labels))
for _, l := range ts.Labels {
m[model.LabelName(l.Name)] = model.LabelValue(l.Value)
for _, s := range ts.Samples {
fmt.Printf(" %f %d\n", s.Value, s.Timestamp)
http.ListenAndServe(":1234", nil)