stefanprodan / swarmprom

Docker Swarm instrumentation with Prometheus, Grafana, cAdvisor, Node Exporter and Alert Manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

modify the prometheus.yml file to add new job

oBaqazi opened this issue · comments

Hi
I am trying to edit prometheus targets in /prometheus/conf/prometheus .yml but the prometheus container did not take the modification. I also try to make volume from /prometheus/conf/prometheus .yml to etc/prometheus/prometheus .yml but it didn't wotk .

1 - prometheus file in /prometheus/conf/prometheus .yml

global:
scrape_interval: 15s
evaluation_interval: 15s

external_labels:
monitor: 'promswarm'

rule_files:

  • "swarm_node.rules.yml"
  • "swarm_task.rules.yml"

alerting:
alertmanagers:

  • static_configs:
    • targets:
      • alertmanager:9093

scrape_configs:

  • job_name: 'prometheus'
    static_configs:

    • targets: ['localhost:9090']
  • job_name: 'dockerd-exporter'
    dns_sd_configs:

    • names:
      • 'tasks.dockerd-exporter'
        type: 'A'
        port: 9323
  • job_name: 'cadvisor'
    dns_sd_configs:

    • names:
      • 'tasks.cadvisor'
        type: 'A'
        port: 8080
  • job_name: 'node-exporter'
    dns_sd_configs:

    • names:
      • 'tasks.node-exporter'
        type: 'A'
        port: 9100
  • job_name: 'centos_node_exporter'
    static_configs:

    • targets: ['10.21.58.73:9100']

2 - prometheus file in the prometheus container /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s

external_labels:
monitor: 'promswarm'

rule_files:

  • "swarm_node.rules.yml"
  • "swarm_task.rules.yml"

alerting:
alertmanagers:

  • static_configs:
    • targets:
      • alertmanager:9093

scrape_configs:

  • job_name: 'prometheus'
    static_configs:

    • targets: ['localhost:9090']
  • job_name: 'dockerd-exporter'
    dns_sd_configs:

    • names:
      • 'tasks.dockerd-exporter'
        type: 'A'
        port: 9323
  • job_name: 'cadvisor'
    dns_sd_configs:

    • names:
      • 'tasks.cadvisor'
        type: 'A'
        port: 8080
  • job_name: 'node-exporter'
    dns_sd_configs:

    • names:
      • 'tasks.node-exporter'
        type: 'A'
        port: 9100

@oBaqazi You'll need to edit docker-compose.yml and add the prometheus.yml file in (2) places inside, a total of (4) lines. Take a look at the configs: section near the top that defines the Docker config metadata, and then look for the configs: section of the prometheus: service definition, you'll see other config label and file examples there to copy to have swarm propagate your file into a container when it's brought up using the 'docker config ls' mechanism.

Also, a volume mounted at ./local_dir:/prometheus/conf would replace everything in that directory, probably not what you want. Either use a Docker config to get your local single file into your container at a specified location, or put your files into ./local_dir and map them into the container in a different place (e.g. /prometheus/local_config) and then modify the docker-compose.yml prometheus: command: - '--config.file=/etc/prometheus/prometheus.yml' to match your new config file.

Also see https://github.com/swarmstack/swarmstack which has the exact config: lines to cut-n-paste to bring a local prometheus.yml file into your container.

Thank you sir , it works