[英]collect metrics from different pods in prometheus
我想從 Kubernetes 的部署(具有多個 pod)中收集指標,我的指標之一是我的部署收到的調用數量,我的問題是關於 Prometheus,我如何告訴 Prometheus 調用所有屬於其中的 pod部署並從他們那里收集指標? 實現這一目標的最佳實踐是什么?
我強烈建議使用prometheus-operator來完成所有繁重的工作,為您的應用程序配置 Prometheus 監控。
例如,有這樣的部署和服務:
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
spec:
replicas: 3
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-app
image: fabxc/instrumented_app
ports:
- name: web
containerPort: 8080
---
kind: Service
apiVersion: v1
metadata:
name: example-app
labels:
app: example-app
spec:
selector:
app: example-app
ports:
- name: web
port: 8080
您可以配置ServiceMonitor
object,它將使用 Service 作為服務發現端點來查找 Deployment 的所有 pod。 這假設您的應用程序使用 HTTP 路徑/metrics
公開指標。
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-app
labels:
team: frontend
spec:
selector:
matchLabels:
app: example-app
endpoints:
- port: web
這將使 Prometheus 為您的應用程序抓取指標。
您可以在此處閱讀有關 ServiceMonitors 的更多信息: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/user-guides/getting-started.md
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.