Từ Code đến System

Linux

Prometheus – Part 2 – Hướng dẫn triển khai Node Export trên Ubuntu 20.04

Tổng quan

Node Exporter là giải pháp VM, Host của Prometheus, sản phẩm được sử dụng để thu thập thông tin về hệ thống và tài nguyên tại máy chủ hoặc các thành phần trong mạng.

Node Exporter sẽ thu thập dữ liệu từ các máy chủ như thông tin CPU, bộ nhớ, dung lượng ổ đĩa, tình trạng mạng và nhiều thông số khác. Nó cung cấp các metric quan trọng để đo lường và theo dõi hiệu suất của hệ thống, từ đó giúp người dùng nhận biết các vấn đề tiềm ẩn và tối ưu hóa hoạt động của các máy chủ.

Với Node Exporter, người dùng có thể tạo ra các báo cáo và biểu đồ để theo dõi hiệu suất của hệ thống theo thời gian và phát hiện sự thay đổi và xu hướng. Nó cũng cung cấp thông cho cho việc cấu hình cảnh báo, cho phép người dùng đặt ngưỡng và nhận thông báo khi các metric vượt qua mức cảnh báo đã định trước.

Phần 1: Cài đặt Node Exporter

Chuẩn bị

Thực hiện cài đặt dịch vụ Prometheus theo docs

  • Cài đặt Ubuntu version 20.04
  • Cấu hình 2 CPU, 2 GB Ram, 50 GB Disk
  • Trong bài, server của mình có IP 192.168.0.113

Bước 1: Tạo user cho node exporter

useradd --no-create-home --shell /bin/false node_exporter

Bước 2: Tải source code

wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
tar xzf node_exporter-1.6.1.linux-amd64.tar.gz
sudo mv -v node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
node_exporter --version

Bước 3: Tạo systemd

sudo vi /etc/systemd/system/node-exporter.service
[Unit]
Description=Node Exporter
After=network.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter --collector.systemd

[Install]
WantedBy=multi-user.target

Bước 4: Khởi tạo dịch vụ

sudo systemctl daemon-reload
sudo systemctl start node-exporter.service
sudo systemctl enable node-exporter.service
sudo systemctl status node-exporter.service

Bước 5: Kiểm tra

http://192.168.0.113:9100/metrics

Phần 2: Cấu hình tại prometheus

Bước 1: Bổ sung thêm File cấu hình

Mở file

sudo vi /etc/prometheus/prometheus.yml

Bổ sung

  - job_name: 'client01'
    scrape_interval: 5s
    static_configs:
    - targets: ['192.168.0.113:9100']

File cấu hình tổng hiện tại

root@prometheus01:~# cat /etc/prometheus/prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'client01'
    scrape_interval: 5s
    static_configs:
    - targets: ['192.168.0.113:9100']

Bước 2: Khởi động lại prometheus

sudo systemctl restart prometheus.service

Bước 3: Kiểm tra

Truy cập graph, kiểm tra metrics

  • http://192.168.0.113:9090/graph
  • {instance=”192.168.0.113:9100″, job=”client01″}

Có metrics –> Cấu hình thành công

Nguồn

https://linuxhint.com/install-prometheus-on-ubuntu/

4 Comments

  1. Dũng

    AD viết bài hay quá. Nhờ AD viết thêm về Elastic – Hệ thống get logs đi AD. Thanks AD.

  2. Mike

    Hi AD,
    Cám ơn bài viết của AD. Mình có làm theo đã thành công. Nay mình đang bị trở ngại ở phần ec2 service discovery sd_prometheus theo tag. Mong AD hướng dẫn giúp mình với. Thanks AD nhiều

Leave a Reply