Skip to content

Prometheus

Mon 01 Jul 2024  
🎉 Hi: ... 🎉

ติดตั้ง prometheus และ node_exporter เพื่อใช้สำหรับการ Monitoring

  • ติดตั้ง Docker ให้เรียบร้อย

  • สร้างไฟล์ docker-compose.yml เพื่อใช้สำหรับ Run docker

yml
networks:
  xxxxx-network:
    external: true

volumes:
  xxxxx-data:
    driver: local

services:
  prometheus:
    image: prom/prometheus:xx.xx.xx
    container_name: prometheus
    restart: always
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus-data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.retention.time=5y'
    ports:
      - 'xxxx:xxxx'
    networks:
      - xxxxx-network

  node_exporter:
    image: prom/node-exporter:xx.xx.xx
    container_name: node_exporter
    restart: always
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.rootfs=/rootfs'
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
    ports:
      - 'xxxx:xxxx'
    networks:
      - xxxxx-network
  • สร้างไฟล์ prometheus.yml เพื่อใช้ตั้งค่า prometheus
yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['xxx:yyy']

  - job_name: 'node'
    static_configs:
      - targets: ['xxx:yyy']
  • ใช้คำสั่ง docker compose เพื่อ run docker compose
bash
  docker compose up -d
  • ทดสอบการทำงานของ node_exporter โดยเข้าไปที่ 192.xxx.xxx.xxx:port ถ้าใช้งานได้จะได้หน้าจอแบบนี้

    node_exporter-01

  • ทดสอบการทำงานของ prometheus โดยเข้าไปที่ 192.xxx.xxx.xxx:port ถ้าใช้งานได้จะได้หน้าจอแบบนี้

    prometheus-01

Built with: VitePress.