简体   繁体   English

Prometheus 添加自定义指标

[英]Prometheus add custom metrics

We have a Prometheus running in our cluster and we are able to use grafana to watch our cluster / pods metrics, now I want to add some custom metrics, is there a way to do it?我们有一个 Prometheus 在我们的集群中运行,我们可以使用 grafana 来查看我们的集群/pods 指标,现在我想添加一些自定义指标,有没有办法做到这一点? if so how should I connect the code to Prometheus, I mean if i write golang program using Prometheus API, and deploy it as docker to k8s, now does the program know to connect with Prometheus?如果是这样,我应该如何将代码连接到 Prometheus,我的意思是如果我使用 Prometheus API 编写 golang 程序,并将其部署为 docker 到 k8s,现在程序是否知道与 Prometheus 连接? eg this program is exposing data to the /metrics endpoint but what else should I do to make prom to be able to read this data?例如,该程序将数据暴露给 /metrics 端点,但我还应该做些什么来使舞会能够读取这些数据?

https://gist.github.com/sysdig-blog/3640f39a7bb1172f986d0e2080c64a75#file-prometheus-metrics-golang-go https://gist.github.com/sysdig-blog/3640f39a7bb1172f986d0e2080c64a75#file-prometheus-metrics-golang-go

You probably want Prometheus to discover the targets to scrape from automatically, if so you should configure K8s service discovery in Prometheus to discover pods, nodes and services from your cluster (maybe you already did something like this since you are already monitoring k8s metrics).您可能希望 Prometheus 自动发现要从中抓取的目标,如果是这样,您应该在 Prometheus 中配置K8s 服务发现以发现集群中的 pod、节点和服务(也许您已经做过类似的事情,因为您已经在监控 k8s 指标)。

To get your go application monitored you can for example add annotations to your pods or to your services to enable scraping from this targets and define where the metrics are available (path, port).要监控您的 go 应用程序,您可以例如向您的 pod 或您的服务添加注释,以启用从该目标中抓取并定义指标可用的位置(路径、端口)。 However this depends on your scrape configuration and relabeling.但是,这取决于您的抓取配置和重新标记。 Good example can be found here很好的例子可以在这里找到

If you are using Prometheus Operator you need to define a servicemonitor resource instead.如果您使用Prometheus Operator ,则需要定义一个 servicemonitor 资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM