最近,prometheus-算子被提升为稳定舵图(https://github.com/helm/charts/tree/master/stable/prometheus-operator).
我想了解如何将自定义应用程序添加到k8s集群中prometheus操作符的监视中。举个例子,比如说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这是prometheus的配置:
> kubectl get prometheus -o yaml
...
serviceMonitorNamespaceSelector: {}
serviceMonitorSelector:
matchLabels:
release: prometheus
...所以选择器应该匹配。所谓“不工作”,我的意思是端点不出现在prometheus中。
发布于 2018-10-26 16:36:27
感谢彼得,他告诉我,原则上它的想法并不完全不正确,我已经找到了缺失的环节。由于servicemonitor确实监视服务(haha),所以我忽略了创建一个不是gitlab图表一部分的服务的部分。最后,这个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运行图中定义的。
发布于 2019-06-01 11:42:08
我知道这个问题已经回答了。但当Prometheus部署在Kubernetes时,我遇到了类似的问题,使用Helm的稳定/prometheus运算符图无法为我的ServiceMonitor找到任何活动目标。事实证明,我的服务公开了一个我没有明确命名的端口:
- protocol: TCP
port: 8080
targetPort: uwsgi我可以以uwsgi端口为目标,在大会中使用它。但是,ServiceMonitor似乎需要在Service中显式命名端口,即使它与自己的tagetPort具有相同的名称:
- name: uwsgi
protocol: TCP
port: 8080
targetPort: uwsgi我写了一篇关于这个问题的博文,这里
发布于 2021-12-22 19:02:31
这张图片完美地展示了普罗米修斯、ServiceMonitors和服务之间的联系。

如果任何匹配不正确,目标就不会出现。
https://stackoverflow.com/questions/52991038
复制相似问题