【发布时间】:2021-04-12 22:58:39
【问题描述】:
这是官方prometheus golang-client示例:
package main
import (
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var cpuTemp = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "cpu_temperature_celsius",
Help: "Current temperature of the CPU.",
})
func init() {
// Metrics have to be registered to be exposed:
prometheus.MustRegister(cpuTemp)
}
func main() {
cpuTemp.Set(65.3)
// The Handler function provides a default handler to expose metrics
// via an HTTP server. "/metrics" is the usual endpoint for that.
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":8080", nil))
}
在此代码中,http 服务器使用promhttp 库。
在使用gin 框架时如何修改指标处理程序?我在documentation 中没有找到答案。
【问题讨论】:
标签: go prometheus go-gin