Files
pos-system/docs/vi/guides/observability.md
Ho Ngoc Hai b104fafa85 Refactor auth-service to iam-service and update related documentation
- Renamed auth-service to iam-service across various files for consistency.
- Updated Dockerfiles, deployment configurations, and documentation to reflect the service name change.
- Enhanced testing commands in documentation to point to the new iam-service.
- Removed outdated auth-service files and configurations to streamline the project structure.
- Improved bilingual documentation for clarity on the new service structure and usage.
2025-12-30 20:54:21 +07:00

90 lines
3.1 KiB
Markdown

# Hướng dẫn Observability Stack
Tài liệu này hướng dẫn cách sử dụng stack observability (Grafana, Prometheus, Loki, Promtail) được tích hợp trong dự án.
## Tổng quan Kiến trúc
Hệ thống bao gồm các thành phần sau:
- **Prometheus**: Thu thập metrics từ các services.
- **Loki**: Thu thập logs.
- **Promtail**: Quét logs từ các Docker container và gửi về Loki.
- **Grafana**: Bảng điều khiển (dashboard) để trực quan hóa metrics (từ Prometheus) và logs (từ Loki).
## Bắt đầu
### Yêu cầu tiên quyết
- Đã cài đặt Docker và Docker Compose.
- Đã có network `microservices-network` (thường được tạo bởi stack chính của ứng dụng hoặc tạo thủ công).
### Khởi chạy Stack
Bạn có thể khởi chạy dễ dàng bằng script có sẵn:
```bash
./scripts/observability/start.sh
```
Hoặc chạy thủ công:
```bash
# Đảm bảo network đã tồn tại
docker network create microservices-network || true
cd infra/observability
docker-compose -f docker-compose.observability.yml up -d
```
Kiểm tra xem các container đã chạy chưa:
```bash
docker ps
```
Bạn sẽ thấy các container `grafana`, `prometheus`, `loki`, và `promtail`.
## Truy cập Dịch vụ
| Dịch vụ | URL | Tài khoản (nếu có) | Mô tả |
| :--- | :--- | :--- | :--- |
| **Grafana** | [http://localhost:3001](http://localhost:3001) | `admin` / `admin` | Dashboard chính để theo dõi. |
| **Prometheus** | [http://localhost:9090](http://localhost:9090) | N/A | Xem metrics thô và trạng thái target. |
| **Loki** | [http://localhost:3100](http://localhost:3100) | N/A | API tổng hợp log (không có giao diện web). |
## Sử dụng Grafana
1. **Đăng nhập**: Truy cập [http://localhost:3001](http://localhost:3001) và đăng nhập với `admin`/`admin`.
2. **Khám phá dữ liệu (Explore)**:
- Chọn biểu tượng **Explore** (hình la bàn) ở thanh bên trái.
- Chọn **Loki** từ menu datasource để tìm kiếm logs.
- Chọn **Prometheus** từ menu datasource để truy vấn metrics.
### Xem Logs (Loki)
Trong giao diện **Explore** với **Loki** đã chọn:
1. Nhấn nút **Label browser**.
2. Chọn một label, ví dụ: `container`.
3. Chọn tên container cụ thể (ví dụ: `iam-service` hoặc `traefik`).
4. Nhấn **Show logs**.
Bạn cũng có thể viết truy vấn LogQL thủ công, ví dụ:
```logql
{container="iam-service"}
```
### Xem Metrics (Prometheus)
Trong giao diện **Explore** với **Prometheus** đã chọn:
1. Nhập tên metric vào ô truy vấn (ví dụ: `up`, `container_memory_usage_bytes`).
2. Nhấn **Run query**.
## Cấu hình
- **Prometheus**: Các rules và targets được cấu hình tại `infra/observability/prometheus/prometheus.yml`.
- **Promtail**: Rules để quét log được cấu hình tại `infra/observability/promtail/promtail-config.yml`.
- **Grafana**: Cấu hình datasources và dashboards provisioning nằm trong `infra/observability/grafana/`.