Logo

Personal Ops Runbook

Personal runbook covering infrastructure operations for Cloud, Kubernetes, OpenStack, and Ceph environments. Includes deployment and teardown procedures, node management, cluster monitoring setup, and incident response workflows compiled from day-to-day operational work. Intended strictly for personal reference — configurations and scripts are environment-specific and not guaranteed to work as-is elsewhere.

Sử dụng Grafana và Prometheus để monitor windows


Để giảm sát được các server Windows, chúng ta cần phải cài đặt wmi_exporter (Agent collectors) để Promethues có thể thu thập được metric từ các server Windows này.

Nếu các bạn chỉ đơn thuần download các agent này cài đặt vào máy chủ Windows thì bạn chỉ có thể thu thập metric ở mức cơ bản, như hình ở bên trên. Dưới dây là hướng dẫn bạn thu thập metric của những services nâng cao cho service Windows. Ví dụ như: AD, DNS, SQL, IIS, …

image

Bước 1: Download wmi_exporter (bản mới nhất thì nó sẽ được đổi tên thành windows_exporter). Anh em chú ý để edit trong file dashboard nha.

Link download Agent: https://github.com/prometheus-community/windows_exporter/releases

Có 2 phiên bản Agent:

wmi_exporter.exe (click to run, dành cho các bạn nào chỉ cần các metric được enable sẵn).

wmi_exporter.msi (dùng để cài đặt thông qua CMD, enable các tính năng thu thập metric nâng cao).

Khi cài agent qua CMD sẽ giúp các bạn chọn lọc thu thập những loại metric nào cần thu thập, giảm các loại metric không cần thiết, có thể thu thập nhiều loại metric hơn mặc định.

Mở port 9115 trên server linux, và windows server.

Bước 2: Mở CMD hoặc Powershell quyền Administrator, bạn có thể sử dụng các bước như dưới để mở nhanh Powershell với quyền Administrator.

image

Di chuyển đến nơi chứa file windows_exporter-0.20.0-386.msi vừa tải về, trường hợp của mình file này đang đặt tại ổ đĩa C:\

image

Bước 3: Chạy comment msiexec với cú pháp như sau:

msiexec /i windows_exporter-0.20.0-386.msi ENABLED_COLLECTORS="ad,adfs,cache,cpu,cpu_info,cs,container,dfsr,dhcp,dns,fsrmquota,iis,logical_disk,logon,memory,msmq,mssql,netframework_clrexceptions,netframework_clrinterop,netframework_clrjit,netframework_clrloading,netframework_clrlocksandthreads,netframework_clrmemory,netframework_clrremoting,netframework_clrsecurity,net,os,process,remote_fx,service,tcp,time,vmware" TEXTFILE_DIR="C:\custom_metrics" LISTEN_PORT="9115"

Nếu không có lỗi xảy ra, bạn sẽ thấy hiển thị nhanh 1 hộp thoại tiến trình cài đặt, cài đặt hoàn thành khi hộp thoại đó biến mất và màn hình Powershell sẽ không có thông báo gì cho bạn như ở dưới.

image

ENABLED_COLLECTORS=các loại metric cần thu thập, tên của loại metric trong hình bên trên

Tùy theo từng loại windows server mà lựa chọn metric cho phù hợp.

Bước 4: Kết quả sau khi cài đặt xong:

image

Bước 5: Kiểm tra metric bạn truy cập như sau: http://ipserver:9115/metrics

image

Bước 6: Cấu hình cho Prometheus.

Tạo job trong prometheus để giám sát Windows Server này với nội dung sau, bạn thêm nội dung sau vào file prometheus.yml. Tại đây mình thêm trường labels vào để dễ dàng filter metric. Tương tự nếu bạn muốn add nhiều server windows trên cùng 1 job, bạn chỉ cần copy đoạn target và edit lại thông tin.

  - job_name: 'HyperV01'
    static_configs:
    - targets: ['192.168.13.236:9115']
      labels:
       hostname: HyperV01
       type: windows
       company: mipec

  - job_name: 'HyperV02'
    static_configs:
    - targets: ['192.168.13.237:9115']
      labels:
       hostname: HyperV02
       type: windows
       company: mipec

  - job_name: 'HyperV03'
    static_configs:
    - targets: ['192.168.13.238:9115']
      labels:
       hostname: HyperV03
       type: windows
       company: mipec

Bước 7: Restart serivce prometheus

systemctl restart prometheus
systemctl status prometheus

Bước 8: Kiểm tra lại host được thêm vào prometheus thành công hay không. Truy cập vào Prometheus sau đó chọn Status, target để kiểm tra.

image

Hãy thử test 1 querry, bạn có kết quả như hình.

image

Bước 9: Tạo Dashboard monitor Windows server trên Grafana.

Vào trang https://grafana.com/grafana/dashboards/14694-windows-exporter-dashboard/ tải file json dashboard về hoặc copy ID của dashboard đó.

image

Truy cập vàoGrafana, sau đó chọn Manage Dashboards như hình:

image

Nếu bạn sử dụng import bằng ID thì hãy điền ID vào như hình dưới.

image

Còn nếu sử dụng import bằng file json thì bạn hãy tải file json của dashboard về và upload nó vào Grafana hoặc copy nội dung file json và dán vào mục 2 và bấm load như hình.

image

Sau khi load xong bạn sẽ thấy thông tin của dashboard, bạn có thể thay đổi tên hoặc folder chứa dashboard và đừng quên chọn datasource của bạn.

Các tham số cần chú ý:

Name : tên của dashboard.

Folder : thư mục chứa dashboard.

UID : số định danh của dashboard, nếu số này trùng thì khi bạn import dashboard củ sẽ bị ghi đè.

image

Đây là kết quả sau khi bạn import dashboard thành công.

image

Như vậy chúng ta có thể ứng dụng hướng dẫn này để giám sát dịch vụ AD, DNS, SQL, IIS, …