prom-aggregation-gateway
prom-aggregation-gateway copied to clipboard
Problem when pushing using golang client - invalid metric name
trafficstars
Version: github.com/prometheus/client_golang v1.5.1
Code:
import (
"github.com/prometheus/client_golang/prometheus/push"
"github.com/prometheus/client_golang/prometheus"
)
pusher := push.New(
"http://localhost:9091",
"foo-job",
).Gatherer(prometheus.DefaultGatherer)
if err := pusher.Push(); err != nil {
fmt.Println(err)
}
Error:
unexpected status code 400 while pushing to http://localhost:9091/metrics/job/foo-job: text format parsing error in line 1: invalid metric name
I’ve not looked at the Pusher package, but “foo-job” is invalid per the spec - minus sign is not allowed.
I am trying out this project, and I am getting a similar error. Same code works with the prometheus push gateway.
Could not push metrics to push gateway. unexpected status code 400 while pushing to http://push-gateway/metrics/job/region_metrics/assets/regions: text format parsing error in line 1: invalid metric name
if err := push.New("http://push-gateway/", "region_metrics").
Collector(metric).
Grouping("assets", "regions").
Push(); err != nil {
log.Printf("metrics.%v - Could not push metrics to push gateway. %v", fn, err)
}
I looked at the package; you need to call .Format(expfmt.FmtText) to meet the expectations of this program (documented here).
I filed https://github.com/prometheus/client_golang/issues/824 for the inconsistency.
Indeed, that fixes the error.