Hello!
I'm using https://github.com/prometheus/client_golang, and pushing metrics
to Pushgateway.
I already tried many things, but every time I want to push a metric, I get
this error:
*"unexpected status code 400 while pushing to URL: text format parsing
error in line 1: expected float as value, got \"\"\n"*
I don't know what else I can change. I wanted to ask if anyone had this
error or knows what I could change to fix it.
This is my simple implementation:
func IncMetric(name string, value float64, tags []string) {
registry = prometheus.NewRegistry()
pusher = push.New("URL", "job_name").Gatherer(registry)
labels := make([]string, 0, len(tags))
values := make([]string, 0, len(tags))
for _, tag := range tags {
elements := strings.SplitN(tag, ":", 2)
labels = append(labels, elements[0])
values = append(values, elements[1])
}
reqCounter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: name,
},
labels,
)
if err := registry.Register(reqCounter); err != nil {
are := &prometheus.AlreadyRegisteredError{}
if errors.As(err, are) {
reqCounter = are.ExistingCollector.(*prometheus.CounterVec)
} else {
logger.Error("Failed to register metric", zap.Error(err))
}
}
reqCounter.WithLabelValues(values...).Add(value)
if err := pusher.Add(); err != nil {
logger.Error("Could not push to Pushgateway", zap.Error(err))
}
}
Thanks in advance.
Ezequiel
--
You received this message because you are subscribed to the Google Groups
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/2ce9bc84-196d-4f74-8910-0796dd843a49n%40googlegroups.com.