如何向 Prometheus 添加额外的抓取配置

问题描述 投票:0回答:3

我想在 Prometheus 中添加额外的抓取配置。我是按照下面的方法来的。

https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md

首先,创建一个文件 prometheus-additional.yaml 并添加新的配置

- job_name: "prometheus"
  static_configs:
  - targets: ["localhost:9090"]

其次,从中创造了一个秘密。

kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --dry-run -oyaml > additional-scrape-configs.yaml

然后使用以下命令创建秘密

kubectl apply -f additional-scrape-configs.yaml -n monitoring

然后在上面的链接中说

“最后,在您的 prometheus.yaml CRD 中引用此附加配置。”

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: prometheus
  labels:
    prometheus: prometheus
spec:
  replicas: 2
  serviceAccountName: prometheus
  serviceMonitorSelector:
    matchLabels:
      team: frontend
  additionalScrapeConfigs:
    name: additional-scrape-configs
    key: prometheus-additional.yaml

在哪里可以找到以上内容?我需要创建一个新的 CRD 吗?我无法更新现有正在运行的部署吗?

kubernetes prometheus
3个回答
4
投票

这在文档中有些错误,你必须使用additionalScrapeConfigsSecret

  additionalScrapeConfigsSecret:
    enabled: true
    name: additional-scrape-configs
    key: prometheus-additional.yaml

否则你会得到错误

cannot unmarshal !!map into []yaml.MapSlice

这里有一个更好的文档: https://github.com/prometheus-community/helm-charts/blob/8b45bdbdabd9b54766c4beb3c562b766b268a034/charts/kube-prometheus-stack/values.yaml#L2691

根据此,您可以添加抓取配置,而无需打包成这样的秘密:

additionalScrapeConfigs: |
  - job_name: "prometheus"
  static_configs:
  - targets: ["localhost:9090"]

0
投票

该文档适用于 prometheus-operator。如果您已经部署了它,您应该拥有您的Prometheus CRD:

kubectl get prometheus -n monitoring

然后您可以完全按照上面所述编辑 Prometheus:在规范中添加 additionalScrapeConfigs 键。 (添加秘密后)

编辑后,新的抓取配置将自动重新加载并应用(conf-reloaders)。


0
投票

检查 prometheus UI,配置/目标应该已经包含您的新 scape 配置,您无需执行任何其他操作

© www.soinside.com 2019 - 2024. All rights reserved.