Skip to content

Instantly share code, notes, and snippets.

@dattp
Last active December 17, 2024 04:45
Show Gist options
  • Save dattp/d3dc796472f7f401f88f3b133a095bf7 to your computer and use it in GitHub Desktop.
Save dattp/d3dc796472f7f401f88f3b133a095bf7 to your computer and use it in GitHub Desktop.
monitoring windows version 1.0

Hướng dẫn cài đặt monitor window server

Mô hình tổng quan

Untitled-2023-08-09-1137

Trên các con windows server cài đặt:

  • windows exporter : Dùng để export các chỉ số của server như cpu, disk, memory, network, os...
  • cAdvisor: Dùng export các chỉ số của contaier trong docker.

Trên server linux:

  • Prometheus: Để collect và lưu trữ các chỉ số được export từ các exporter.
  • Grafana: Để tạo các dashboard theo dõi hệ thống. Dữ liệu được lấy từ prometheus.

Cài đặt chi tiết

windows exporter

Cài trên cả 4 con server: 130, 131, 135, 136.

Tạo 1 thư mục monitoring tại ổ D.

Download windows exporter tại https://github.com/prometheus-community/windows_exporter/releases.

Tạo file config.yml dùng để chỉ định các chỉ số cần theo dõi có nội dung:

collectors:
  enabled: cpu,cs,logical_disk,physical_disk,net,os,service,system,iis,memory,process

Install windows_exporter vừa tải xuống chạy dưới dạng service. (Lưu ý: chọn đúng đường dẫn trỏ về file config.yml)

Kiểm tra kết quả bằng cách truy cập vào đường dẫn http://{ip-server}:9182/metrics sẽ thấy dữ liệu được trả về.

cAdvisor

Cài trên 2 con server có chạy docker là 130 và 131

Tạo 1 thư mục cAdvisor và file docker-compose.yaml:

version: '3.2'
services:
  cadvisor:
    image: gcr.io/cadvisor/cadvisor:latest
    container_name: cadvisor
    privileged: true
    ports:
    - 9111:8080
    volumes:
    - /:/rootfs:ro
    - /var/run:/var/run:rw
    - /sys:/sys:ro
    - /var/lib/docker/:/var/lib/docker:ro

docker-compose up -d để run container theo dõi các chỉ số của các contaier chay docker.

Kiểm tra kết quả bằng cách truy cập vào đường dẫn http://{ip-server}:9111/metrics sẽ thấy dữ liệu được trả về.

Prometheus + Grafana

Đã được dựng sẵn trên con linux 102 với các bước như sau: (Đây là cách dựng trên linux)

Chạy duy nhất bằng 1 file docker-compose.yml

version: '3.7'

volumes:
  prometheus_data: {}
  grafana_data: {}

networks:
  bridge:
    external: true
    name: my_bridge

services:

  prometheus:
    image: prom/prometheus:v2.50.0
    volumes:
      - ./prometheus/:/etc/prometheus/
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/usr/share/prometheus/console_libraries'
      - '--web.console.templates=/usr/share/prometheus/consoles'
    ports:
      - 9090:9090
    links:
      - cadvisor:cadvisor
      - alertmanager:alertmanager
    depends_on:
      - cadvisor
    #      - pushgateway
    networks:
      - bridge
    restart: always
  alertmanager:
    image: prom/alertmanager
    ports:
      - 9093:9093
    volumes:
      - ./alertmanager/:/etc/alertmanager/
    networks:
      - bridge
    restart: always
    command:
      - '--config.file=/etc/alertmanager/config.yml'
      - '--storage.path=/alertmanager'
  grafana:
    image: grafana/grafana
    user: "472"
    depends_on:
      - prometheus
    volumes:
      - grafana_data:/var/lib/grafana
      - ./grafana/provisioning/:/etc/grafana/provisioning/
    env_file:
      - ./grafana/config.monitoring
    networks:
      - bridge
    restart: always

  nginx_grafana:
    image: nginx:alpine
    depends_on:
      - grafana
    volumes:
      - ./nginx_conf/default.conf:/etc/nginx/conf.d/default.conf
      - ./nginx_conf/nginx.conf:/etc/nginx/nginx.conf
    restart: always
    networks:
      - bridge
    ports:
      - 3000:80

Có 4 service:

prometheus: Dùng để collect và store data từ windows exportercAdvisor.

alertmanager: Dùng để setup các cảnh báo.

grafana: Dùng để trực quan hoá các chỉ số của hệ thống.

nginx_grafana: Dùng để routing request từ ngoài internet vào grafana.

prometheus

Config của prometheus được cấu hình như sau:

# my global config
global:
  scrape_interval: 15s # By default, scrape targets every 15 seconds.
  evaluation_interval: 15s # By default, scrape targets every 15 seconds.
  # 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: "my-project"

# Load and evaluate rules in this file every 'evaluation_interval' seconds.
rule_files:
  - "alert.rules"

# alert
alerting:
  alertmanagers:
    - scheme: http
      static_configs:
        - targets:
            - "alertmanager:9093"

# 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"

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "cadvisor"

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    dns_sd_configs:
      - names:
          - "tasks.cadvisor"
        type: "A"
        port: 8080
  # windows
  - job_name: "cadvisor-130"
    scrape_interval: 15s
    metrics_path: /metrics
    static_configs:
      - targets: ["192.168.50.130:9111"]
        labels:
          group: "DiemDanhThongMinh"
  - job_name: "cadvisor-131"
    scrape_interval: 15s
    metrics_path: /metrics
    static_configs:
      - targets: ["192.168.50.131:9111"]
        labels:
          group: "DiemDanhThongMinh"

  - job_name: "win-exporter-130"
    scrape_interval: 5s
    static_configs:
      - targets: ["192.168.50.130:9182"]
        labels:
          group: "DiemDanhThongMinh"

  - job_name: "win-exporter-131"
    scrape_interval: 5s
    static_configs:
      - targets: ["192.168.50.131:9182"]
        labels:
          group: "DiemDanhThongMinh"

  - job_name: "win-exporter-135"
    scrape_interval: 5s
    static_configs:
      - targets: ["10.14.26.135:9182"]
        labels:
          group: "DiemDanhThongMinh"

  - job_name: "win-exporter-136"
    scrape_interval: 5s
    static_configs:
      - targets: ["10.14.26.136:9182"]
        labels:
          group: "DiemDanhThongMinh"

Chỉ rõ các job_name sẽ scrape data từ các server nào, ở đây chỉ định 4 con server 130, 131, 135, 136.

Grafana

Truy cập vào url và đăng nhập vào tài khoản đã được cung cấp

Lựa chọn dashboard vào import dashboard cần thiết, các dashboard được cung cấp sẵn thì xem tại https://grafana.com/grafana/dashboards/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment