📖 Tổng quan
Trong quá trình vận hành hệ thống sử dụng Ceph Orchestrator (cụ thể là cephadm
) để quản lý dịch vụ giám sát như node-exporter
, đôi khi chúng ta cần bổ sung metric tùy chỉnh (custom metric) – điều mà các collector mặc định không cung cấp.
Trong bài viết này, mình sẽ hướng dẫn chi tiết cách bật và sử dụng tính năng --collector.textfile.directory
trong node-exporter
thông qua extra_entrypoint_args
– một tính năng mới được hỗ trợ trong Ceph >= 18.2.x. Qua đó, bạn có thể ghi các metric của riêng mình từ các script Bash, Python, hoặc bất kỳ ứng dụng nào xuất ra định dạng Prometheus .prom
.
🧐 Tại sao lại cần textfile_collector
?
Trong Prometheus ecosystem, node_exporter
là một agent mạnh mẽ để thu thập thông tin hệ thống. Tuy nhiên, khi bạn cần thu thập:
- Kết quả từ một script đo hiệu suất riêng,
- Thông tin ứng dụng nội bộ không được expose qua HTTP,
- Các giá trị tổng hợp định kỳ (như tổng số job đang chạy, cảnh báo nội bộ),
… thì textfile_collector
chính là cầu nối hoàn hảo để bạn viết metric tùy chỉnh vào một file .prom
.
echo 'custom_metric 42' > /etc/node-exporter/textfile_collector/custom.prom
Mỗi lần node_exporter
thu thập metric, nó sẽ đọc tất cả file .prom
trong thư mục textfile_collector
.
⚙️ Cách cấu hình textfile_collector
trong Ceph Orchestrator
🔧 Bước 1: Export cấu hình node-exporter
ceph orch ls node-exporter --export > node-exporter.yml
Bạn sẽ được một file YAML có nội dung gần như sau:
service_type: node-exporter
service_name: node-exporter
placement:
host_pattern: '*'
✍️ Bước 2: Chỉnh sửa để thêm extra_entrypoint_args
Thêm cấu hình sau:
extra_entrypoint_args:
- "--collector.textfile.directory=/rootfs/etc/node-exporter/textfile_collector"
Toàn bộ file sau khi chỉnh:
service_type: node-exporter
service_name: node-exporter
placement:
host_pattern: '*'
extra_entrypoint_args:
- "--collector.textfile.directory=/rootfs/etc/node-exporter/textfile_collector"
💡 Lưu ý: /rootfs/...
là đường dẫn mount từ host vào container trong Ceph. Đường dẫn /etc/node-exporter/textfile_collector
trên container tương ứng với /var/lib/ceph/.../etc/node-exporter/textfile_collector
trên host.
🚀 Bước 3: Apply lại cấu hình
ceph orch apply -i node-exporter.yml
📁 Bước 4: Tạo thư mục textfile_collector
trên các node
Trên tất cả các node có node-exporter
, bạn cần:
mkdir -p /var/lib/ceph/<fsid>/node-exporter.<hostname>/etc/node-exporter/textfile_collector
chown 65534:65534 /var/lib/ceph/<fsid>/node-exporter.<hostname>/etc/node-exporter/textfile_collector
Bạn có thể xác định <fsid>
và <hostname>
từ lệnh:
podman ps | grep node-exporter
🔍 Kiểm tra hoạt động
Check inspect container sau khi apply cấu hình, bạn sẽ thấy ở list Args
sẽ xuất hiện cờ "--collector.textfile.directory=/etc/node-exporter/textfile_collector"
. Tới đây xem như 99% thành công.
shell> podman inspect ceph-75ac298c-0653-11f0-a2e7-2b96c52a296a-node-exporter-CEPH-LAB-MON-071 | grep -A 9 '"Args"'
"Args": [
"--",
"/bin/node_exporter",
"--no-collector.timex",
"--web.listen-address=:9112",
"--path.procfs=/host/proc",
"--path.sysfs=/host/sys",
"--path.rootfs=/rootfs",
"--collector.textfile.directory=/etc/node-exporter/textfile_collector"
],
✨ Ví dụ 1: Ghi metric thử nghiệm
echo 'my_custom_metric{label="demo"} 123.45' | sudo tee /var/lib/ceph/<fsid>/node-exporter.<hostname>/etc/node-exporter/textfile_collector/demo.prom
🔍 Ví dụ 2: Xem metric qua Prometheus HTTP endpoint
curl http://<ip-node>:9112/metrics | grep my_custom_metric
🧩 Sơ đồ minh họa hoạt động
[Script bên ngoài] --> ghi file .prom
|
v
/etc/node-exporter/textfile_collector/
|
v
[node_exporter] ---> expose metric ---> Prometheus scrape
🔄 Ưu điểm
- ✅ Không cần chỉnh container thủ công: Tránh việc container bị ghi đè khi Ceph upgrade.
- ✅ Tự động áp dụng toàn bộ cluster: Quản lý tập trung qua Ceph Orchestrator.
- ✅ Dễ bảo trì và mở rộng: Có thể áp dụng script metric cho nhiều node.
- ✅ Tăng tính tùy biến cho giám sát: Viết metric cho bất kỳ điều gì bạn muốn.
⚠️ Nhược điểm
- ❗ Đường dẫn trên host tương đối phức tạp, cần xác định đúng.
- ❗ Chỉ hỗ trợ cho
node-exporter
, không áp dụng choosd
,mon
,mgr
. - ❗ Phải quản lý quyền chính xác (
65534:65534
) để node-exporter đọc được.
🔁 So sánh với chỉnh container thủ công
Tiêu chí | Qua Orchestrator (extra args) | Chỉnh container trực tiếp |
---|---|---|
An toàn khi upgrade | ✅ | ❌ |
Dễ tái áp dụng toàn cluster | ✅ | ❌ |
Tính linh hoạt | ✅ | ✅ |
Bảo trì đơn giản | ✅ | ❌ |
💡 Lời khuyên
- Dùng cron hoặc systemd để chạy script tạo metric định kỳ (1p/lần).
- Đặt tên file
.prom
cẩn thận, không nên ghi đè vô tình. - Có thể kiểm thử metric script bằng Prometheus Text Format trước khi triển khai thực tế.
- Luôn test trước trên 1 node trước khi triển khai toàn cluster.
📚 Tham khảo
✅ Kết luận
Việc cấu hình textfile_collector
cho node-exporter
qua Ceph Orchestrator là một giải pháp hiệu quả, an toàn và có khả năng mở rộng cao để đưa các metric tùy chỉnh vào hệ thống giám sát.
Nếu bạn đang sử dụng Ceph >= 18.2.x và muốn nâng tầm khả năng quan sát hệ thống, đây là một bước cấu hình nên làm sớm. 💪
Happy Monitoring! 🚀