package main
import (
"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:
return
case <-ticker.C:
ExamplePusher_Push()
}
}
}
Was this page helpful?