Hello!
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