我已经通过 Helm Chart 安装了 kube-prometheus-stack。 需要为普罗米修斯添加额外的抓取配置。 创建了一个配置映射来从 grok-exporter 中抓取指标
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus
data:
prometheus.yml: |-
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'grok'
static_configs:
- targets: ['grok-exporter:9144']
应用了此配置图。 然后使用以下命令从此配置映射创建秘密
""kubectl create secret generic grok-prometheus --from-file=grok-prometheus.yaml"
秘密已创建。 然后在kube-prometheus-stack的values.yaml中添加additionalScrapeConfigSecrets。
additionalScrapeConfigsSecret:
enabled: true
name: grok-prometheus
key: grok-prometheus.yaml
升级 helmchart 后
当我检查“kubectl get prometheus -o yaml”时,可以看到添加了额外的ScrapeConfig。
spec:
additionalScrapeConfigs:
key: grok-prometheus.yaml
name: grok-prometheus
但是我在普罗米修斯输出中收到以下错误。
- lastTransitionTime: "2022-07-30T16:45:41Z"
message: |-
creating config failed: generating config failed: generate additional scrape configs: unmarshalling additional scrape configs failed: yaml: unmarshal errors:
line 1: cannot unmarshal !!map into []yaml.MapSlice
reason: ReconciliationFailed
status: "False"
type: Reconciled
任何人都可以帮我解决这个问题吗? 预先感谢。
似乎是 ConfigMap 中的缩进问题。
targets
应比 static_configs
深一级。试试这个 YAML。
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus
data:
prometheus.yml: |-
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'grok'
static_configs:
- targets: ['grok-exporter:9144']
秘密不应该是 ConfigMap,而应该是抓取配置条目,如下所示: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md
- job_name: 'grok'
static_configs:
- targets: ['grok-exporter:9144']
根据此,您可以添加抓取配置,而无需打包成这样的秘密:
additionalScrapeConfigs: |
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
额外的ScrapeConfigs:
其他Scrape配置:|
我尝试了这些配置,但没有任何效果。我正在尝试为 cassandra-exporter 设置抓取配置。
我已经在kube-prometheus-stack helm-chart的values.yaml文件中完成了上述配置https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/ Chart.yaml
我可以尝试其他任何事情,还是我缺少上述配置中的任何内容。