golang 接 promethus + grafana

150 阅读1分钟

1 应用数据上报 promethus

import(
    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promauto"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)

go func() {
		http.Handle("/metrics", promhttp.Handler())
		http.ListenAndServe(":2112", nil)
	}()

2 安装+启动 promethus 参考文档:segmentfault.com/a/119000002…

3 promethus 进程和应用打通 修改 promethus 配置文件中的 target 为 localhost:2112

4 安装+启动 grafana 参考文档:segmentfault.com/a/119000002…

5 grafana 设置可匿名登录且权限为只读 修改 /etc/grafana/grafana.ini 设置如下:

[auth.anonymous]  


# enable anonymous access  


enabled = true  


# specify organization name that should be used for unauthenticated users  


org_name = Main Org.  


# specify role for unauthenticated users  


org_role = Viewer