Deployment of Prometheus and Grafana in the Docker Environment
I will use docker-compose to up Prometheus, Grafana Server, and node exporter in any machine you want to export the metrics.
Pre-requisite
Docker and Docker Compose should installed.
Let’s start the work
create a file called compose.yml
`
version: '3.9'
services:
prometheus:
container_name: prometheus
image: ubuntu/prometheus:2.50.0-22.04_stable
ports:
- "9090:9090"
volumes:
- /home/kali/ws/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml
environment:
- TZ=UTC
networks:
- monitoring
grafana:
container_name: grafana
image: grafana/grafana
ports:
- "3000:3000"
volumes:
- grafana-vol:/var/lib/grafana
networks:
- monitoring
networks:
monitoring:
volumes:
grafana-vol:
now, create a file called `prometheus.yml` and paste the below data, here only replace this with your path of prometheus.yml `/home/kali/ws/monitoring/prometheus.yml`
# 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).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# 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: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "ec2_1"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["192.168.75.205:9100"]
here below is the template you have to use to add any node
- job_name: "ec2_1"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["192.168.75.205:9100"]
docker compose up -d
to start the container, and don’t forget to restart the container after updating prometheus.yml file
Just paste the IP and port number of the node exporter, and Prometheus will scroll the matrices.
Connect the Grafana from your browser on port number 3000
and login with the default username and password admin
and click on configure data source and give the IP and port number of the Prometheus server.
2. Download and Start the Node Exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar xvfz node_exporter-*.*-amd64.tar.gz
cd node_exporter-*.*-amd64
./node_exporter
Run this command in any Linux host to enable metrics collection.
After running the above command take the IP and port number and open the prometheus.yml
add their name, IP, and port number so that Prometheus can curl the metrics.
That’s all about metrics solution to deploy in docker, this is basic and simple to start with after this you can use a backup strategy for Prometheus and Grafana and other industry-standard good practices,
I’ll talk in later blogs.