Search code examples
prometheus

How to add multiple scrape URLs to prometheus.yml?


I want to use Grafana/Prometheus to collect metrics from components. Grafana, Prometheus, node_exporter, Wildfly are running fine.

I want to collect metrics from:

  • http://localhost:9090/metrics (Prometheus itself)
  • http://localhost:9182/metrics (node exporter)
  • http://localhost:9990/metrics (Wildfly)
  • http://localhost:8080/application/rest/metrics (my application inside Wildfly)

How to configure it in prometheus.yml? I tried the following, but this does not work:

scrape_configs:
  - job_name: "prometheus"
    metrics_path: "/metrics"
    static_configs:
      - targets: ["localhost:9100", "localhost:9990", "localhost:9090"]
        labels:
            group: 'system'
  - job_name: "application"
    metrics_path: "/application/rest/metrics"
    static_configs:
      - targets: ["localhost:8080"]
        labels:
            group: 'application'

Solution

  • Please try this configuration:

    scrape_configs:
      - job_name: prometheus
        static_configs:
          - targets: ['localhost:9090']
      - job_name: node_exporter
        static_configs:
          - targets: ['localhost:9182']
      - job_name: wildfly
        static_configs:
          - targets: ['localhost:9990']
      - job_name: application
        metrics_path: '/application/rest/metrics'
        static_configs:
          - targets: ['localhost:8080']