【问题标题】:Monitor custom kubernetes pod metrics using Prometheus Operator使用 Prometheus Operator 监控自定义 kubernetes pod 指标
【发布时间】:2021-02-12 01:28:28
【问题描述】:
我有一个现成的 Kubernetes 集群,配置了 grafana + prometheus(operator) 监控。
我使用我的应用向 pod 添加了以下标签:
prometheus.io/scrape: "true"
prometheus.io/path: "/my/app/metrics"
prometheus.io/port: "80"
但指标不会进入 Prometheus。但是,prometheus 拥有所有默认的 Kubernetes 指标。
有什么问题?
【问题讨论】:
标签:
kubernetes
devops
prometheus
prometheus-operator
【解决方案1】:
你应该创建ServiceMonitor or PodMonitor objects。
ServiceMonitor 描述了 Prometheus 要监控的目标集。 Operator 根据定义自动生成 Prometheus 抓取配置,target 将拥有服务背后所有 Pod 的 IP。
例子:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-app
labels:
team: frontend
spec:
selector:
matchLabels:
app: example-app
endpoints:
- port: web
PodMonitor,它以声明方式指定应如何监视 pod 组。 Operator 根据定义自动生成 Prometheus 抓取配置。
例子:
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: example-app
labels:
team: frontend
spec:
selector:
matchLabels:
app: example-app
podMetricsEndpoints:
- port: web