英文:
How do I target endpoints with specific ports in prometheus
问题
我正在尝试配置Prometheus以针对命名空间中的Kubernetes Pod,但只针对端口8081,尽管Pod同时暴露了8080和8081端口。使用这个配置:
- job_name: 'api'
metrics_path: "/actuator/prometheus"
kubernetes_sd_configs:
- role: endpoints
namespaces:
names:
- "api"
我会为每个Pod获得两个目标 - 每个端口一个。我无法弄清楚如何进一步缩小目标,仅限于8081端口。感谢任何关于此的帮助!
英文:
I'm trying to configure prometheus to target kubernetes pods in a namespace, but only port 8081, even though the pods expose both 8080 and 8081. With this configuration:
- job_name: 'api'
metrics_path: "/actuator/prometheus"
kubernetes_sd_configs:
- role: endpoints
namespaces:
names:
- "api"
I get two targets for each pod - one for each port. I can't figure out how to narrow down the targets further to just the 8081 ports. Thanks for any help with this!
答案1
得分: 2
您可以使用kubernete_sd_configs中的正则表达式来匹配您要定位的端口和端点。示例:
- job_name: my_job
metrics_path: /metrics
kubernetes_sd_configs:
- roles: endpoints
namespaces:
name:
- api
relabel_configs:
- source_labels: [_meta_kubernetes_service_name,_meta_kubernetes_endpoint_port_name]
regex: my_service;8081
在这里,我们使用正则表达式来匹配带有服务名称为my_service
和端口号为8081
的端点。如果您需要从不同的端点抓取指标,那么您需要相应地修改正则表达式。
确保在您的Kubernetes服务上提到适当的服务发现注释,以确保Prometheus可以使用kubernetes_sd_configs来发现它们。
欲了解更多信息,请查看由Lou Marvin Caraig编写的这篇博客。
查看这个Prometheus论坛的讨论以获取更多信息。
英文:
You can use the regex in kubernete_sd_configs to match the port and endpoint you are trying to target.
Example :
- job_name: my_job
metrics_path: /metrics
kubernetes_sd_configs:
- roles: endpoints
namespaces:
name:
- api
relable_configs:
- source_labels: [_meta_kubernetes_service_name,_meta_kubernetes_endpoint_port_name]
regex: my_service;8081
Here we are using regex to match the endpoints with the service name called my_service
and port number 8081
. If you need to scrape the metrics from different endpoints then you need to modify the regular expression accordingly.
Make sure you mentioned appropriate service discovery annotations on your kubernetes services to ensure the prometheus can discover them using kubernetes_sd_configs.
For more information have a glance at this blog written by Lou Marvin Caraig.
Check this prometheus forum discussion for more inputs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论