简体   繁体   English

从 prometheus 中的不同 pod 收集指标

[英]collect metrics from different pods in prometheus

i want to collect metrics from a deployment (with multiple pods) from Kubernetes, and on of my metrics is the number of calls that my deployment received, my question is about Prometheus, how can i tell Prometheus to call all the pods that are part of the deployment and collect metrics from them?我想从 Kubernetes 的部署(具有多个 pod)中收集指标,我的指标之一是我的部署收到的调用数量,我的问题是关于 Prometheus,我如何告诉 Prometheus 调用所有属于其中的 pod部署并从他们那里收集指标? And what is the best practice to achieve this goal?实现这一目标的最佳实践是什么?

I would highly recommend using prometheus-operator to do all heavy lifting with configuring Prometheus monitoring for your applications.我强烈建议使用prometheus-operator来完成所有繁重的工作,为您的应用程序配置 Prometheus 监控。

For example, having the Deployment and Service like this:例如,有这样的部署和服务:

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

You may configure ServiceMonitor object which will use Service as a service discovery endpoint to find all the pods of the Deployment.您可以配置ServiceMonitor object,它将使用 Service 作为服务发现端点来查找 Deployment 的所有 pod。 This assumes that your application is exposing metrics using HTTP path /metrics .这假设您的应用程序使用 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

This will make Prometheus scrape metrics for your application.这将使 Prometheus 为您的应用程序抓取指标。

You may read more about ServiceMonitors here: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/user-guides/getting-started.md您可以在此处阅读有关 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