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)
    }

}

 

上一篇:安装K8S命令补全工具


下一篇:git命令自动补全