weaveworks / prom-aggregation-gateway

An aggregating push gateway for Prometheus
Mozilla Public License 2.0
328 stars 61 forks source link

go client doesn't work #53

Open pingwangrh opened 3 years ago

pingwangrh commented 3 years ago

trying the example code from go client doc: https://pkg.go.dev/github.com/prometheus/client_golang/prometheus/push?utm_source=godoc#Pusher.Push

it works with the normal pushgateway, but if I point the url to prom-aggregation-gateway, got error: Could not push to Pushgateway: unexpected status code 400 while pushing to http://localhost:8080/metrics/job/ping_test: text format parsing error in line 1: expected float as value, got ""

package main

import (
    "fmt"

    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/push"
)

func main() {
    completionTime := prometheus.NewGauge(prometheus.GaugeOpts{
        Name: "db_backup_last_completion_timestamp_seconds",
        Help: "The timestamp of the last successful completion of a DB backup.",
    })
    completionTime.SetToCurrentTime()
    if err := push.New("http://pushgateway:9091", "ping_test").
        Collector(completionTime).
        Grouping("db", "customers").
        Push(); err != nil {
        fmt.Println("Could not push completion time to Pushgateway:", err)
    }
}
tomcyr commented 3 years ago

I have the same issue, but changed format:

.Format(expfmt.FmtText)

it works for me.

pingwangrh commented 3 years ago

I have the same issue, but changed format:

.Format(expfmt.FmtText)

it works for me.

Yeah, changing format works. Thank you so much!

pingwangrh commented 3 years ago

duplicated with https://github.com/weaveworks/prom-aggregation-gateway/issues/48