prometheus client_golang pushgateway error

64 views
Skip to first unread message

Ezequiel Gonzalez

unread,
Jul 1, 2023, 9:05:07 AM7/1/23
to Prometheus Users
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
Reply all
Reply to author
Forward
0 new messages