小编mrq*_*sch的帖子

为 golang prometheus 收集器添加标签

我想弄清楚如何为普罗米修斯收集器添加标签。任何想法我在这里失踪?我有两个文件:main.go 和collector.go

我使用以下链接作为指南。https://rsmitty.github.io/Prometheus-Exporters/

我模拟了这个例子,所以我可以把它贴在这里。我最终不会为命令提取“日期 +%s”。就是不知道在哪里添加标签。

对于标签,我正在尝试添加主机名,因此结果如下:

# HELP cmd_result Shows the cmd result
# TYPE cmd_result gauge
cmd_result{host="my_device_hostname"} 1.919256141363144e-76
Run Code Online (Sandbox Code Playgroud)

我对 golang 也很陌生,所以我很有可能把这一切都弄错了!我最终试图让普罗米修斯在每次刮擦时提取 cmd 结果。

main.go

package main

import (
    "net/http"

    log "github.com/Sirupsen/logrus"
    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {

    //Create a new instance of the collector and
    //register it with the prometheus client.
    cmd := newCollector()
    prometheus.MustRegister(cmd)

    //This section will start the HTTP server and expose
    //any metrics on the /metrics endpoint.
    http.Handle("/metrics", promhttp.Handler())
    log.Info("Beginning to serve on port :8080") …
Run Code Online (Sandbox Code Playgroud)

go prometheus

6
推荐指数
1
解决办法
7614
查看次数

标签 统计

go ×1

prometheus ×1