Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

How to monitor the server with Prometheus and Grafana by Docker

Nguyễn Hữu Hưng edited this page Apr 16, 2021 · 1 revision

1. Requirements

  • Ubuntu
  • Docker (Need to know) but you don't know, it's okay, just skip this tutorial =)

2. Install

docker run -d \
  --net="host" \
  --pid="host" \
  -v "/:/host:ro,rslave" \
  quay.io/prometheus/node-exporter:latest \
  --path.rootfs=/host

For Docker compose, similar flag changes are needed.

version: '3.8'

services:
  node_exporter:
    image: quay.io/prometheus/node-exporter:latest
    container_name: node_exporter
    command:
      - '--path.rootfs=/host'
    network_mode: host
    pid: host
    restart: unless-stopped
    volumes:
      - '/:/host:ro,rslave'

On some systems, the timex collector requires an additional Docker flag, --cap-add=SYS_TIME, in order to access the required syscalls.

Volumes & bind-mount

docker run \
    -p 9090:9090 \
    -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus

Or bind-mount the directory containing prometheus.yml onto /etc/prometheus by running:

docker run \
    -p 9090:9090 \
    -v /path/to/config:/etc/prometheus \
    prom/prometheus

protheus.yml

global:
  scrape_interval: 5s
  external_labels:
    monitor: 'node'
scrape_configs:
  - job_name: 'prometheus' 
    static_configs: 
      - targets: ['(ipLAN or PublicIP):9090'] ## IP Address of the localhost recommended
  - job_name: 'node-exporter' 
    static_configs: 
      - targets: ['(ipLAN or PublicIP):9100'] ## IP Address of the localhost recommended

Docker (Don't execute it, if you don't understand)

docker run -d --name prometheus -p 9090:9090 -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
docker run -d -p 3000:3000 grafana/grafana

Watch this video to continue: https://youtu.be/uCYfDtR9S9k?t=269

@ds112, @onepiecehung

Clone this wiki locally