[英]How to show custom application metrics in Prometheus captured using the golang client library from all pods running in Kubernetes
I am trying to get some custom application metrics captured in golang using the prometheus client library to show up in Prometheus. 我正在尝试使用prometheus客户端库在golang中捕获一些自定义应用程序指标,以显示在Prometheus中。
I have the following working: 我有以下工作:
I have a go application which is exposing metrics on localhost:8080/metrics as described in this article: 我有一个go应用程序,它按本文所述在localhost:8080 / metrics上公开指标:
https://godoc.org/github.com/prometheus/client_golang/prometheus https://godoc.org/github.com/prometheus/client_golang/prometheus
I have a kubernates minikube running which has Prometheus, Grafana and AlertManager running using the operator from this article: 我有一个运行的kubernates minikube,其中有Prometheus,Grafana和AlertManager使用本文的运算符运行:
https://github.com/coreos/prometheus-operator/tree/master/contrib/kube-prometheus https://github.com/coreos/prometheus-operator/tree/master/contrib/kube-prometheus
I created a docker image for my go app, when I run it and go to localhost:8080/metrics I can see the prometheus metrics showing up in a browser. 我为go应用创建了一个docker映像,当我运行它并转到localhost:8080 / metrics时,我可以看到Prometheus指标显示在浏览器中。
I use the following pod.yaml to deploy my docker image to a pod in k8s 我使用以下pod.yaml将docker映像部署到k8s中的pod
apiVersion: v1 kind: Pod metadata: name: my-app-pod labels: zone: prod version: v1 annotations: prometheus.io/scrape: 'true' prometheus.io/port: '8080' spec: containers: - name: my-container image: name/my-app:latest imagePullPolicy: IfNotPresent ports: - containerPort: 8080
kubectl exec -it my-app-pod -- /bin/bash
kubectl exec -it my-app-pod-/ bin / bash
then do wget on "localhost:8080/metrics", I can see my metrics 然后在“ localhost:8080 / metrics”上执行wget,我可以看到我的指标
So far so good, here is where I am hitting a wall. 到目前为止一切顺利,这是我碰壁的地方。 I could have multiple pods running this same image.
我可以让多个Pod运行同一张图片。 I want to expose all the images to prometheus as targets.
我想将所有图像公开给普罗米修斯作为目标。 How do I configure my pods so that they show up in prometheus so I can report on my custom metrics?
如何配置我的广告连播,使其以普罗米修斯的形式出现,以便我可以报告自定义指标?
Thanks for any help offered! 感谢您提供的任何帮助!
The kubernetes_sd_config directive can be used to discover all pods with a given tag. kubernetes_sd_config指令可用于发现具有给定标签的所有Pod。 Your Prometheus.yml config file should have something like so:
- job_name: 'some-app' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] regex: python-app action: keep
您的Prometheus.yml配置文件应具有以下内容:
- job_name: 'some-app' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] regex: python-app action: keep
The source label [__meta_kubernetes_pod_label_app] is basically using the Kubernetes api to look at pods that have a label of 'app' and whose value is captured by the regex expression, given on the line below (in this case, matching 'python-app'). 源标签[__meta_kubernetes_pod_label_app]基本上是使用Kubernetes api来查看具有标签“ app”且其值由正则表达式表达式捕获的Pod,在下一行给出(在本例中,匹配“ python-app” )。
Once you've done this Prometheus will automatically discover the pods you want and start scraping the metrics from your app. 完成此操作后,Prometheus将自动发现所需的Pod,并开始从您的应用程序中收集指标。
Hope that helps. 希望能有所帮助。 You can follow blog post here for more detail.
您可以在此处关注博客文章,以获取更多详细信息。
Note: it is worth mentioning that at the time of writing, kubernetes_sd_config is still in beta. 注意:值得一提的是,在编写本文时,kubernetes_sd_config仍处于beta中。 Thus breaking changes to configuration may occur in future releases.
因此,将来的发行版中可能会发生对配置的重大更改。
Can you share the prometheus config that you are using to scrape the metrics. 您能否共享用于刮擦度量标准的prometheus配置。 The config will control what all sources to scrape the metrics from.
该配置将控制从哪些来源中获取指标。 Here are a few links that you can refer to : https://groups.google.com/forum/#!searchin/prometheus-users/Application $20metrics$20monitoring$20of$20Kubernetes$20Pods%7Csort:relevance/prometheus-users/uNPl4nJX9yk/cSKEBqJlBwAJ
您可以参考以下几个链接: https ://groups.google.com/forum/#!searchin/prometheus-users/Application $ 20metrics $ 20monitoring $ 20of $ 20Kubernetes $ 20Pods%7Csort:relevance / prometheus-users / uNPl4nJX9yk / cSKEBqJlBwAJ
You need 2 things: 您需要两件事:
There is an example in the docs over here: https://coreos.com/operators/prometheus/docs/latest/user-guides/running-exporters.html 此处的文档中有一个示例: https : //coreos.com/operators/prometheus/docs/latest/user-guides/running-exporters.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.