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()
      // completionTime.Set(200)  // set可以設置任意值(float64)
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)
    }

}

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM