如何为普罗米修斯操作员创建ServiceMonitor? [英] How to create a ServiceMonitor for prometheus-operator?
本文介绍了如何为普罗米修斯操作员创建ServiceMonitor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想了解如何在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
...
所以选择器应该匹配。我所说的"不工作"是指端点不会出现在普罗米修斯的用户界面中。
推荐答案
多亏了Peter,他告诉我这个想法在原则上并不完全正确,我找到了缺失的环节。由于servicemonitor
确实监控服务(哈哈),我错过了创建一个不属于GitLab掌舵图的服务的部分。最后,这个YAML帮了我的忙,指标显示在普罗米修斯中:
# 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跑步者图表中定义。
这篇关于如何为普罗米修斯操作员创建ServiceMonitor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文