第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在戈朗的普羅米修斯出口器中添加直方圖?

如何在戈朗的普羅米修斯出口器中添加直方圖?

Go
慕的地8271018 2022-10-04 19:34:22
下面是我的代碼示例?,F(xiàn)在我想在我的代碼中添加直方圖。但是我找不到像這樣添加直方圖的方法。有人可以幫助我嗎?我能夠編寫(xiě)直方圖示例,但我無(wú)法將其添加到下面的代碼中package mainimport (    "github.com/prometheus/client_golang/prometheus"    "github.com/prometheus/client_golang/prometheus/promhttp"    "github.com/prometheus/common/log"    "net/http")type fooCollector struct {    fooMetric *prometheus.Desc}func newFooCollector(label1 string) *fooCollector {    return &fooCollector{        fooMetric: prometheus.NewDesc("fff_metric",            "Shows whether a foo has occurred in our cluster",            nil, prometheus.Labels{"env":label1},        ),            }}func (collector *fooCollector) Describe(ch chan<- *prometheus.Desc) {    //Update this section with the each metric you create for a given collector    ch <- collector.fooMetric}func (collector *fooCollector) Collect(ch chan<- prometheus.Metric) {    ch <- prometheus.MustNewConstMetric(collector.fooMetric, prometheus.GaugeValue, 111111)}func main() {    prometheus.MustRegister(newFooCollector("dev"))    http.Handle("/metrics", promhttp.Handler())    http.ListenAndServe(":80", nil)}
查看完整描述

1 回答

?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊

最后我學(xué)會(huì)了直方圖是如何工作的,這是我的代碼


package main


import (

    "github.com/prometheus/client_golang/prometheus"

    "github.com/prometheus/client_golang/prometheus/promhttp"

    "net/http"

)


type fooCollector struct {

    fooMetric *prometheus.Desc

}

//First,we define the variable of histogram

var (

    hbrms_histovec = prometheus.NewHistogramVec(

        prometheus.HistogramOpts{

            Name:        "hbrms_histogram",

            Help:        "hbrms_histogram",

            ConstLabels: prometheus.Labels{"constname": "constvalue"},

            Buckets: prometheus.ExponentialBuckets(50, 1.3, 15),//50*1.3,15times

        },

        []string{"env"},

    )


)


func newFooCollector() *fooCollector {

    return &fooCollector{

        fooMetric: prometheus.NewDesc("fff_metric",

            "Shows whether a foo has occurred in our cluster",

            nil, nil,

        ),

    }

}


func (collector *fooCollector) Describe(ch chan<- *prometheus.Desc) {

    ch <- collector.fooMetric

}


func (collector *fooCollector) Collect(ch chan<- prometheus.Metric) {

    ch <- prometheus.MustNewConstMetric(collector.fooMetric, prometheus.CounterValue, float64(1))

    // 2nd,we set metrics in this way instead of write to channel,we just find a way of calling the code below when we visit the url.

    hbrms_histovec.WithLabelValues("val1").Observe(float64(10))

}


func main() {

    reg := prometheus.NewPedanticRegistry()

    reg.MustRegister(newFooCollector())

    // finally,we register the metrics "hbrms_histovec" in this way

    reg.MustRegister(hbrms_histovec)

    gatherers := prometheus.Gatherers{reg}


    h := promhttp.HandlerFor(gatherers,

        promhttp.HandlerOpts{

            ErrorHandling: promhttp.ContinueOnError,

        })


    http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {

        h.ServeHTTP(w, r)

    })

    http.ListenAndServe(":80", nil)

}


查看完整回答
反對(duì) 回復(fù) 2022-10-04
  • 1 回答
  • 0 關(guān)注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)