terraformprometheusjmx-exporter

Prometheus helm values deployed via Terraform does not load the file specified in file_sd_configs block


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.


Solution

  • 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