firasKoubaa
firasKoubaa

Reputation: 6867

Prometheus & Grafana running on local env : How to link grafana container to prometheus container in local

i'm setting up Promtheus & Grafana of my local Ubuntu machine as docker containers ,

my steps were :

  1. running prometheus : docker run -t -d -p 9090:9090 prom/prometheus
  2. running Grafana : docker run -t -d --name grafana -p 3000:3000 grafana/grafana

as you can see prometheus run on the mapped 9090 port , same for grafana running on 3000

Now when configuring grafana dashborad for prometheus in grafana , i need to indicate the url of prometheus :

-> since both of them are running on local containers.

What address ton give to grafana to make it point on prometheus ?

Upvotes: 0

Views: 2355

Answers (3)

Amine Zaine
Amine Zaine

Reputation: 185

Your Grafana container will not be able to contact (discover) your Prometheus container because when docker starts each container, it creates a virtual interface on host system with unique name like vethef766ac, and isolates the containers.

If you don't want to use docker compose AND if you want to access your Grafana container using its host IP, you have to run your Grafana container in the host network using the --network option.

You can then run Grafana as so:

docker run -t -d --name grafana --network="host" grafana/grafana

Note: --network="host" gives the container full access to local system services such as D-bus and is therefore considered insecure.

The URL you will want to specify in Grafana would be http://localhost:9090.

Upvotes: 1

ankidaemon
ankidaemon

Reputation: 1363

For a running docker container if needs to look for their address, following command can be helpful.

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container-name>

This will return an IP address associated.

Upvotes: 0

wolmi
wolmi

Reputation: 1709

For an easy setup, you can use docker-compose as commented. An example of docker-compose.yaml file with prometheus and grafana:

docker-compose.yaml

version: "3"
services:
  prometheus:
    image: prom/prometheus:latest
    volumes:
      - ./prometheus.yaml:/etc/prometheus/prometheus.yml
    ports:
      - 9090:9090
  grafana:
    image: grafana/grafana:latest
    volumes:
      - ./grafana-storage:/var/lib/grafana
      - ./grafana/config.ini:/etc/grafana/config.ini
      - ./grafana/provisioning:/etc/grafana/provisioning
      - ./grafana/dashboards:/var/lib/grafana/dashboards
    ports:
      - 3001:3000

prometheus.yaml

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'codelab-monitor'

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first.rules"
  # - "second.rules"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'your-app'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ['your-app:3000']

config.ini

[paths]
provisioning = /etc/grafana/provisioning

[server]
enable_gzip = true

[users]
default_theme = light

Upvotes: 1

Related Questions