sundapeng c098f1d3ce dev_1.0.0_sundp 完成Metric模块及模块e2e测试 (#18)
Co-authored-by: sundapeng.sdp <sundapeng@hashdata.cn>
Reviewed-on: #18
Reviewed-by: xuxt <xuxt@zgclab.edu.cn>
Reviewed-by: yuyr <yuyr@zgclab.edu.cn>
Reviewed-by: huhy <husteryezi@163.com>
2025-10-11 17:15:06 +08:00

100 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Grafana 构建配置
基于 `grafana/grafana:11.1.0` 构建的自定义镜像,主要做了用户 ID 适配和配置自动化。
## 快速开始
```bash
# 构建镜像
docker build -t argus-metric-grafana:1.0.0 .
# 启动容器(主机网络模式)
docker run -d \
--name grafana \
--network=host \
-v /private/argus:/private/argus \
argus-metric-grafana:1.0.0
```
访问:`http://localhost:3001/private/argus/metric/grafana/`
默认账号:`admin` / `admin`
## 用户 ID 配置
镜像默认使用特殊的用户 ID 以适配主机权限:
- `GRAFANA_UID=2133`
- `GRAFANA_GID=2015`
如果需要修改,构建时传入参数:
```bash
docker build \
--build-arg GRAFANA_UID=1000 \
--build-arg GRAFANA_GID=1000 \
-t argus-metric-grafana:1.0.0 .
```
## 配置说明
### 数据源配置
修改 `datasources/datasources.yml` 中的 Prometheus 地址:
```yaml
datasources:
- name: Prometheus
type: prometheus
url: http://10.211.55.5:9090 # 改成你的 Prometheus 地址
isDefault: true
```
**注意**:确保 Grafana 容器能访问到 Prometheus 服务,网络要通。
### Dashboard 导入
配置好数据源后,手动导入默认 dashboard
1. 登录 Grafana
2. 左侧菜单 → Dashboards → Import
3. 上传 `dashboards/default_dashboard.json`
4. 选择 Prometheus 数据源
5. Import
或者直接把 dashboard 放到持久化目录:
```bash
cp dashboards/default_dashboard.json /private/argus/metric/grafana/provisioning/dashboards/
```
重启容器会自动加载(因为 `dashboards.yml` 配置了自动扫描该目录)。
## 目录结构
持久化目录都在 `/private/argus` 下:
```
/private/argus/
├── etc/
│ └── grafana.metric.argus.com # 容器 IP 记录
└── metric/grafana/
├── config/
│ └── grafana.ini # 主配置文件
├── data/ # 数据库、会话等
├── logs/ # 日志
├── plugins/ # 插件
└── provisioning/
├── datasources/
│ └── datasources.yml # 数据源配置
└── dashboards/
├── dashboards.yml # dashboard 配置
└── *.json # dashboard JSON 文件
```
## 启动流程
容器启动时 `start-grafana-supervised.sh` 会:
1. 记录容器 IP 到 `/private/argus/etc/grafana.metric.argus.com`
2. 创建必要的目录
3.`/tmp/` 复制配置文件到持久化目录(首次启动或配置不存在时)
4. 用 `grafana:grafana` (UID:GID=2133:2015) 启动 Grafana 服务