繁体   English   中英

从 prometheus 中的不同 pod 收集指标

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM