gpt4 book ai didi

kubernetes - 如何为 prometheus-operator 创建 ServiceMonitor?

转载 作者:行者123 更新时间:2023-12-02 22:37:07 27 4
gpt4 key购买 nike

最近,prometheus-operator 已升级为稳定的 Helm Chart ( https://github.com/helm/charts/tree/master/stable/prometheus-operator )。

我想了解如何添加自定义应用程序以通过 k8s 集群中的 prometheus-operator 进行监控。举个 gitlab runner 的例子,默认情况下提供 9252 上的指标( https://docs.gitlab.com/runner/monitoring/#configuration-of-the-metrics-http-server )。

我有一个基本的 yaml,显然不起作用,但也没有提供任何关于不起作用的反馈:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: gitlab-monitor
# Change this to the namespace the Prometheus instance is running in
namespace: default
labels:
app: gitlab-runner-gitlab-runner
release: prometheus
spec:
selector:
matchLabels:
app: gitlab-runner-gitlab-runner
namespaceSelector:
# matchNames:
# - default
any: true
endpoints:
- port: http-metrics
interval: 15s

这是普罗米修斯配置:

> kubectl get prometheus -o yaml

...
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector:
matchLabels:
release: prometheus
...

所以选择器应该匹配。我所说的“不工作”是指端点不会出现在 prometheus UI 中。

最佳答案

感谢彼得,他向我展示了这个想法原则上并不完全错误,我找到了缺失的链接。由于 servicemonitor 确实监视服务(哈哈),我错过了创建不属于 gitlab helm 图表的服务的部分。最后这个 yaml 帮了我的忙,指标出现在 Prometheus 中:

# Service targeting gitlab instances
apiVersion: v1
kind: Service
metadata:
name: gitlab-metrics
labels:
app: gitlab-runner-gitlab-runner
spec:
ports:
- name: metrics # expose metrics port
port: 9252 # defined in gitlab chart
targetPort: metrics
protocol: TCP
selector:
app: gitlab-runner-gitlab-runner # target gitlab pods
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: gitlab-metrics-servicemonitor
# Change this to the namespace the Prometheus instance is running in
# namespace: default
labels:
app: gitlab-runner-gitlab-runner
release: prometheus
spec:
selector:
matchLabels:
app: gitlab-runner-gitlab-runner # target gitlab service
endpoints:
- port: metrics
interval: 15s

很高兴知道:metrics targetPort 在 gitlab runner 图表中定义。

关于kubernetes - 如何为 prometheus-operator 创建 ServiceMonitor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52991038/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com