英文:
Prometheus helm values deployed via Terraform does not load the file specified in file_sd_configs block
问题
我正在遵循这个指南: https://docs.aws.amazon.com/msk/latest/developerguide/open-monitoring.html,它可以启用 Prometheus 使用 JMX Exporter 从 MSK 集群获取指标。
教程提到要创建一个 targets.json 文件,并在稍后填充它的值,然后你需要使用以下方式加载该文件:
- job_name: 'broker'
file_sd_configs:
- files:
- 'targets.json'
我的当前 Prometheus 配置文件如下,但似乎无法将 "targets.json" 文件加载到 Prometheus 配置中:
extraScrapeConfigs: |
- job_name: broker
file_sd_configs:
- files:
- targets.json
我是否需要在 Terraform 中插入一些内容以使其识别这个外部文件?
指定绝对文件路径似乎不起作用。
英文:
I am following this guide: https://docs.aws.amazon.com/msk/latest/developerguide/open-monitoring.html which enables prometheus to grab metrics from MSK Cluster using JMX Exporter
The tutorial mentions to create a targets.json file and populate it with your values later on, you need to load that file with:
- job_name: 'broker'
file_sd_configs:
- files:
- 'targets.json'
My current prometheus values file looks like this, but seems like I can't load the targets.json
file into the prometheus configuration
extraScrapeConfigs: |
- job_name: broker
file_sd_configs:
- files:
- targets.json
Do I need to interpolate something in between for Terraform to recognize this external file?
Specifying the absolute file path does not seem to work.
答案1
得分: 0
最终成功解决了这个问题。我遵循了这个方法:
正如您所看到的,我需要使用 ConfigMap 资源加载 "targets.json" 文件。这是我用于 Prometheus 图表的 Helm 值:
extraScrapeConfigs: |
- job_name: targets
file_sd_configs:
- files:
- /etc/prometheus/exports/targets.json
server:
extraConfigmapMounts:
- name: targets
mountPath: /etc/prometheus/exports
subPath: ""
configMap: targetsfile
readOnly: true
ConfigMap 资源创建如下:
resource "kubernetes_config_map" "targets" {
metadata {
name = "targetsfile"
namespace = "monitoring"
}
data = {
"targets.json" = "${file("${path.module}/targets.json")}"
}
}
按照这些步骤,您可以成功加载 "targets.json" 文件到 "prometheus-server" 容器中。
英文:
Finally managed to fix this. I've followed this approach:
As you can see I needed to load the targets.json
file with a ConfigMap resource. These are the helm values I've used for the prometheus chart:
extraScrapeConfigs: |
- job_name: targets
file_sd_configs:
- files:
- /etc/prometheus/exports/targets.json
server:
extraConfigmapMounts:
- name: targets
mountPath: /etc/prometheus/exports
subPath: ""
configMap: targetsfile
readOnly: true
The ConfigMap resource gets created as:
resource "kubernetes_config_map" "targets" {
metadata {
name = "targetsfile"
namespace = "monitoring"
}
data = {
"targets.json" = "${file("${path.module}/targets.json")}"
}
}
Following those steps, you can succesfully load into the prometheus-server
pod the targets.json
file
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论