如何在Service monitor中设置标签,使其显示在Prometheus度量中



我想在类似服务监视器的键值映射中设置targetLabels,以便它出现在Prometheus度量中。我试着在服务监视器上重新贴标签,但没用。

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-application
labels:
team: backend-team
spec:
selector:
matchLabels:
app: example-application
endpoints:
- port: backend
relabelings:
- sourceLabels: [__name__]
regex: (.*)
targetLabel: teamname
replacement: "backend-team"
action: replace

我还发现了targetLabels。但不知道如何使用它。TargetLabels在Kubernetes服务上传输标签到目标上。

我还读到在服务监视器中可能有白名单标签。请让我知道如何做到这一点,以及哪种方法是正确的选择。。

在Servicemonitor规范中,我们需要添加targetlabels,以便将服务标签传播到Prometheus。

具有";teamname";标签:

kind: Service
apiVersion: v1
metadata:
name: example-application
labels:
app: example-application
teamname: neon
spec:
selector:
app: example-application
ports:
- name: backend
port: 8080

示例Servicemonitor传播";teamname";来自服务的标签:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-application
namespace: monitoring
spec:
selector:
matchLabels:
app: example-application
endpoints:
- port: backend
path: /prometheus
namespaceSelector:
matchNames:
- testns
targetLabels:
- teamname
- app

最新更新