其他分享
首页 > 其他分享> > golang实现向pushgateway推送数据

golang实现向pushgateway推送数据

作者:互联网

package commands

import (
    "fmt"

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


func main() {
    ExamplePusher_Push()
}

func ExamplePusher_Push() {
    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://127.0.0.1:9091", "db_backup").   // push.New("pushgateway地址", "job名称")
        Collector(completionTime).  // Collector(completionTime) 给指标赋值
        Grouping("db", "customers").Grouping("instance", "1.1.1.1").  // 给指标添加标签,可以添加多个
        Push(); err != nil {
        fmt.Println("Could not push completion time to Pushgateway:", err)
    }

}

 

标签:completion,db,golang,prometheus,completionTime,pushgateway,push,推送
来源: https://www.cnblogs.com/wt11/p/15527340.html