Prometheus Helm values通过Terraform部署时,不会加载file_sd_configs块中指定的文件。

huangapple go评论64阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月9日 05:04:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76435675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定