无法从其他Go文件更新Prometheus指标值

时间:2019-12-06 09:00:05

标签: go prometheus prometheus-node-exporter

当我从其他go进程调用inc(),add()时,度量标准值不会更新。

server.go

package main

import (
    "github.com/prometheus/client_golang/prometheus/promhttp"
    "github.com/prometheus/common/log"
    "net/http"
)


func main() {
    http.Handle("/metrics", promhttp.Handler())
    log.Infoln("Metrics Server Started at 7189")
    log.Fatal(http.ListenAndServe(":7189", nil))
}

metrics.go

package main

import "github.com/prometheus/client_golang/prometheus"

var JobGauge = prometheus.NewGauge(
        prometheus.GaugeOpts{
            Namespace: "queue",
            Name: "no_of_live_jobs",
            Help: "This value gives number of of jobs in queue",
        })

func init() {
    prometheus.MustRegister(JobGauge)
    JobGauge.Set(0)
}

client.go

package main

func main() {
    JobGauge.Add(10)
}

当我确实从server.go的量规中增加了价值时,它的工作效果很好。但是,当我从client.go添加要测量的值时,该值没有被添加。我在这里想念什么?

先谢谢了。

0 个答案:

没有答案