Go to content Go to menu Go to search

Установка Prometheus + node-exporter + Grafana в docker-compose

Установить Prometheus + node-exporter + Grafana в docker-compose

docker-compose.yml:

version: '3.3'
services:
  node_exporter:
    image: quay.io/prometheus/node-exporter:v1.3.1
    container_name: core2-sb-mongo-lt-n1
    command:
      - '--path.rootfs=/host'
    pid: host
    restart: unless-stopped
    volumes:
      - '/:/host:ro,rslave'
    ports:
      - "9100:9100"

  prometheus:
      image: prom/prometheus:v2.37.0
      container_name: prometheus
      volumes:
          - ./prometheus.yml:/etc/prometheus/prometheus.yml
          - ./prometheus-data:/prometheus
      command:
          - '--config.file=/etc/prometheus/prometheus.yml'
      ports:
          - '9090:9090'
#      extra_hosts:
#          - "core2-sb-mongo-lt-n2:188.165.25.103"
#          - "core2-sb-mongo-lt-n3:188.165.137.10"
#          - "core2-prototype-mongodb-bs-lt:10.77.7.51"

  grafana:
      image: grafana/grafana:8.5.10
      container_name: grafana
      volumes:
          - "./grafana-data:/var/lib/grafana"
      environment:
          - GF_SECURITY_ADMIN_PASSWORD=<PASSWORD>
      links:
          - prometheus
      ports:
          - "3000:3000"

networks:
    default:

prometheus.yml

global:
    scrape_interval: 10s
    external_labels:
        monitor: 'lambda-monitor'
scrape_configs:
    - job_name: node
      static_configs:
      - targets: ['core2-sb-mongo-lt-n1:9100', 'core2-sb-mongo-lt-n2:9100', 'core2-sb-mongo-lt-n3:9100','core2-prototype-mongodb-bs-lt:9100']

node-exporter.service

[Unit]
Description=node-exporter
Requires=docker.service
After=docker.service

[Service]
WorkingDirectory=/srv/docker/node_exporter
#ExecStartPre=/usr/bin/docker-compose pull
ExecStart=/usr/bin/docker compose up
ExecStop=/usr/bin/docker compose down
TimeoutStartSec=30
TimeoutStopSec=10
Restart=on-failure
StartLimitBurst=3
TimeoutStartSec=120
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target

Дашборд для Grafana:

NodeExporter.zip

Установить node-exporter на другой сервер linux:

Скачать и установить:

curl -s https://api.github.com/repos/prometheus/node_exporter/releases/latest| grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
tar -xvf node_exporter*.tar.gz
cd  node_exporter*/
sudo cp node_exporter /usr/local/bin

Создать юнит-файл для systemd /etc/systemd/system/node_exporter.service:

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
useradd -rs /bin/false node_exporter

[Service]
User=node_exporter
Group=node_exporter
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=default.target

Настроить автозапуск:

systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter

Проверить:

curl http://localhost:9100/metrics


при публикации материалов с данного сайта обратная ссылка на сайт обязательна.
valynkin.ru © no rights reserved