POST /api/v1/prom/write
$IP, $PORT, $APPID, and $TOKEN to the authentication information of your own instance, which can be queried in the console.$INSTANCE with an identifier of the current machine, such as IP/Hostname. If this groupingKey is not set, when multiple machines report data together, the data entries will overwrite each other.package mainimport ("fmt""time""github.com/prometheus/client_golang/prometheus""github.com/prometheus/client_golang/prometheus/push""github.com/prometheus/common/expfmt")var completionTime = prometheus.NewGauge(prometheus.GaugeOpts{Name: "db_backup_last_completion_timestamp_seconds",Help: "The timestamp of the last successful completion of a DB backup.",})func do() {completionTime.SetToCurrentTime()}func ExamplePusher_Push() {if err := push.New("http://$IP:$PORT", "db_backup").BasicAuth("$APPID", "$TOKEN").Collector(completionTime).Grouping("instance", "$INSTANCE").Grouping("db", "customers").Format(expfmt.FmtText).Push(); err != nil {fmt.Println("Could not push completion time to Pushgateway:", err)}}func main() {do()ticker := time.NewTicker(2 * time.Second)done := make(chan bool)for {select {case <-done:returncase <-ticker.C:ExamplePusher_Push()}}}
Client method for the object generated by push.New. We recommend you set an appropriate timeout period. In addition, if data is pushed, we recommend you use an async method for calls so as to avoid blocking the primary business process.Feedback