ToiVietBlog - Bài này mình sẽ hướng dẫn các bạn monitor VMware với Prometheus vmware_exporter.
Việc sử dụng VMware tại các công ty là khá phổ biến. Vì vậy, việc monitor hạ tầng VMware cũng là điều cần thiết.
Lưu ý: mình thực hiện trên vcenter chứ không thực hiện trên 1 host riêng lẻ.
Điều đầu tiên, bạn cần tạo sẵn một user read-only trên vcenter dùng để monitor hệ thống.
Recommended Reading: Tạo user Read-only trong VMware Vcenter 6.7
Hệ điều hành mà mình sử dụng là Ubuntu server 18.04, mình cài vmware_exporter chung trên server chạy prometheus.
Cài đặt vmware_exporter
Để cài đặt vmware_exporter, bạn cần python3 và pip3. Bạn có thể kiểm tra thông qua lệnh dưới.
python3 --version pip3 --verion
Nếu 2 lệnh trên không trả về kết quả, bạn cần cài đặt 2 gói này cho server.
apt install python3 -y apt install python3-pip -y
Bây giờ, bạn chạy lệnh dưới để cài đặt vmware_exporter.
pip3 install vmware_exporter pip3 install --ignore-installed PyYAML
Sau khi cài xong, thư mục chứa source vmware_exporter nằm ở /usr/local/lib/python3.6/dist-packages/vmware_exporter
.
Tiếp theo, bạn cần tạo file config cho vmware_exporter.
nano /usr/local/lib/python3.6/dist-packages/vmware_exporter/config.yml
Sau đó, bạn copy nội dung dưới vào file.
default: vsphere_host: vcenter.yourdomain.com vsphere_user: '[email protected]' vsphere_password: 'usermonitorpass' ignore_ssl: True specs_size: 5000 fetch_custom_attributes: True fetch_tags: True fetch_alarms: True collect_only: vms: True vmguests: True datastores: True hosts: True snapshots: True
Bạn thay thông tin trong phần config ở trên với thông tin vcenter thực tế của bạn.
Sau đó, bạn tạo file service systemd cho vmware_exporter.
nano /etc/systemd/system/vmware_exporter.service
Copy nội dung dưới vào file.
[Unit] Description=Prometheus VMWare Exporter Wants=network-online.target After=network-online.target [Service] Type=simple User=root Group=root ExecReload=/bin/kill -HUP $MAINPID ExecStart=/usr/bin/python3 /usr/local/bin/vmware_exporter -c /usr/local/lib/python3.6/dist-packages/vmware_exporter/config.yml SyslogIdentifier=vmware_exporter Restart=always [Install] WantedBy=multi-user.target
Reload daemon và khởi động dịch vụ.
systemctl daemon-reload systemctl enable vmware_exporter.service systemctl start vmware_exporter.service
Thiết lập Prometheus cho vmware_exporter
Sau khi bạn cài đặt vmware_exporter xong theo các bước ở trên, bạn cần thiết lập prometheus gọi tới cổng dịch vụ của vmware_exporter.
nano /etc/prometheus/prometheus.yml
Bạn thêm nội dung dưới vào file.
- job_name: 'dc_vcenter' scrape_timeout: 1m scrape_interval: 2m metrics_path: '/metrics' static_configs: - targets: - 'vcenter.yourdomain.com' relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: localhost:9272
Tiếp theo, bạn tìm trong file prometheus.yml đoạn như dưới và thêm file rule cho vcenter.
rule_files: # - "first_rules.yml" # - "second_rules.yml" - "/etc/prometheus/rules/vcenter.yml"
Tới đây, bạn chưa restart hay reload dịch vụ prometheus vội. Bạn cần tạo file rule cho vcenter nữa.
Thiết lập rule alertmanager cho vmware

Recommended Reading: Cài đặt Alertmanager và thiết lập cảnh báo Prometheus
Bạn tạo một file chứa các rule alert cho vcenter.
nano /etc/prometheus/rules/vcenter.yml
Bạn copy nội dung giống như dưới vào file, mình chỉ trích đoạn đầu file, bạn có thể tải file đầy đủ tại link gitlab này.
groups: - name: Vcenter ESXi Host rules: - alert: Connect Vcenter Failed expr: up{job="dc_vcenter"} == 0 for: 10s labels: severity: "Critical" annotations: Summary: 'Connect "{{ $labels.instance }}" failed.'
Bây giờ bạn reload dịch vụ prometheus và dịch vụ alertmanager.
systemctl reload prometheus systemctl reload alertmanager
Bây giờ thì bạn có thể mở trình duyệt, truy cập trang Prometheus để xem các thông tin target, alert của vcenter đã có chưa.
Thiết lập Grafana dashboard
Recommended Reading: Cài đặt Prometheus và Grafana trên Ubuntu 18
Phần cuối cùng là thiết lập giao diện Grafana để monitor VMware.
Mình đã thử qua một số dashboard tìm trên Grafana và mình thấy hiện tại chỉ có ID 11243
là có thể dùng được.
Nếu bạn muốn sử dụng 1 bản mình đã custom, thêm một số bảng thông tin thì bạn có thể tải file json tại đây.
Các bạn thông cảm là mình không tiện chụp trực tiếp dashboard lên được, vì nó chứa nhiều thông tin nhạy cảm.
Kết luận
Qua bài viết này, mình đã hướng dẫn các bạn lần lượt đầy đủ các bước để có thể monitor VMware. Tạo user monitor trên vcenter, cài đặt exporter, thiết lập prometheus, thiết lập alert rule, thiết lập dashboard grafana.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.