feat: add apisix/etcd/grafana/prometheus

This commit is contained in:
Sun-ZhenXing
2025-09-26 16:40:04 +08:00
parent 8e096fb9a7
commit 30014852ca
17 changed files with 1473 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
# Prometheus Environment Variables
# Prometheus image version
PROMETHEUS_VERSION=v3.5.0
# Host port mapping (maps to Prometheus port 9090 in container)
PROMETHEUS_PORT_OVERRIDE=9090
# How long to retain data (examples: 15d, 30d, 1y)
PROMETHEUS_RETENTION_TIME=15d
# Maximum storage size (empty = unlimited, examples: 10GB, 1TB)
PROMETHEUS_RETENTION_SIZE=
# External URL for Prometheus (used for links and redirects)
PROMETHEUS_EXTERNAL_URL=http://localhost:9090

119
src/prometheus/README.md Normal file
View File

@@ -0,0 +1,119 @@
# Prometheus
[English](./README.md) | [中文](./README.zh.md)
This service deploys Prometheus, an open-source system monitoring and alerting toolkit with a multi-dimensional data model and powerful query language.
## Services
- `prometheus`: The Prometheus server for scraping and storing time series data.
## Environment Variables
| Variable Name | Description | Default Value |
| ------------------------- | ------------------------------------------------------------- | ----------------------- |
| PROMETHEUS_VERSION | Prometheus image version | `v3.5.0` |
| PROMETHEUS_PORT_OVERRIDE | Host port mapping (maps to Prometheus port 9090 in container) | `9090` |
| PROMETHEUS_RETENTION_TIME | How long to retain data | `15d` |
| PROMETHEUS_RETENTION_SIZE | Maximum storage size (empty = unlimited) | `""` |
| PROMETHEUS_EXTERNAL_URL | External URL for Prometheus (used for links and redirects) | `http://localhost:9090` |
Please modify the `.env` file as needed for your use case.
## Volumes
- `prometheus_data`: A volume for storing Prometheus time series data.
- `prometheus.yml`: Optional custom configuration file (mount to `/etc/prometheus/prometheus.yml`).
- `rules`: Optional directory for alerting and recording rules (mount to `/etc/prometheus/rules`).
## Default Configuration
The default Prometheus configuration includes:
- Scraping itself for metrics
- Global scrape interval of 15 seconds
- Basic web console access
## Configuration Files
### Custom Prometheus Configuration
Mount a custom `prometheus.yml` file to `/etc/prometheus/prometheus.yml`:
```yaml
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
```
Example `prometheus.yml`:
```yaml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['node_exporter:9100']
```
### Alert Rules
Mount rules directory to `/etc/prometheus/rules`:
```yaml
volumes:
- ./rules:/etc/prometheus/rules
```
## Data Retention
Configure data retention using environment variables:
- `PROMETHEUS_RETENTION_TIME`: Time-based retention (e.g., `30d`, `1y`)
- `PROMETHEUS_RETENTION_SIZE`: Size-based retention (e.g., `10GB`, `1TB`)
## API Access
- Web UI: `http://localhost:9090`
- API endpoint: `http://localhost:9090/api/v1/`
- Admin API is enabled for configuration reloads
## Security Notes
- Consider restricting access to the admin API in production
- Use authentication/authorization proxy for production deployments
- Monitor resource usage as Prometheus can consume significant storage and memory
## Common Use Cases
### Monitoring Docker Containers
Add cAdvisor to monitor container metrics:
```yaml
services:
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
ports:
- "8080:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
```
### Service Discovery
Use file-based service discovery or integrate with service discovery systems like Consul or Kubernetes.
## License
Prometheus is licensed under the Apache 2.0 license.

119
src/prometheus/README.zh.md Normal file
View File

@@ -0,0 +1,119 @@
# Prometheus
[English](./README.md) | [中文](./README.zh.md)
本服务部署 Prometheus这是一个开源的系统监控和警报工具包具有多维数据模型和强大的查询语言。
## 服务
- `prometheus`: 用于抓取和存储时间序列数据的 Prometheus 服务器。
## 环境变量
| 变量名 | 描述 | 默认值 |
| ------------------------- | --------------------------------------------------- | ----------------------- |
| PROMETHEUS_VERSION | Prometheus 镜像版本 | `v3.5.0` |
| PROMETHEUS_PORT_OVERRIDE | 主机端口映射(映射到容器中的 Prometheus 端口 9090 | `9090` |
| PROMETHEUS_RETENTION_TIME | 数据保留时间 | `15d` |
| PROMETHEUS_RETENTION_SIZE | 最大存储大小(空值 = 无限制) | `""` |
| PROMETHEUS_EXTERNAL_URL | Prometheus 的外部 URL用于链接和重定向 | `http://localhost:9090` |
请根据您的使用情况修改 `.env` 文件。
## 数据卷
- `prometheus_data`: 用于存储 Prometheus 时间序列数据的数据卷。
- `prometheus.yml`: 可选的自定义配置文件(挂载到 `/etc/prometheus/prometheus.yml`)。
- `rules`: 用于警报和记录规则的可选目录(挂载到 `/etc/prometheus/rules`)。
## 默认配置
默认的 Prometheus 配置包括:
- 抓取自身的指标
- 全局抓取间隔为 15 秒
- 基本的 Web 控制台访问
## 配置文件
### 自定义 Prometheus 配置
将自定义 `prometheus.yml` 文件挂载到 `/etc/prometheus/prometheus.yml`
```yaml
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
```
示例 `prometheus.yml`
```yaml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['node_exporter:9100']
```
### 警报规则
将规则目录挂载到 `/etc/prometheus/rules`
```yaml
volumes:
- ./rules:/etc/prometheus/rules
```
## 数据保留
使用环境变量配置数据保留:
- `PROMETHEUS_RETENTION_TIME`: 基于时间的保留(例如,`30d``1y`
- `PROMETHEUS_RETENTION_SIZE`: 基于大小的保留(例如,`10GB``1TB`
## API 访问
- Web UI: `http://localhost:9090`
- API 端点: `http://localhost:9090/api/v1/`
- 启用了管理 API 用于配置重新加载
## 安全注意事项
- 考虑在生产环境中限制对管理 API 的访问
- 为生产部署使用身份验证/授权代理
- 监控资源使用情况,因为 Prometheus 可能消耗大量存储和内存
## 常见用例
### 监控 Docker 容器
添加 cAdvisor 来监控容器指标:
```yaml
services:
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
ports:
- "8080:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
```
### 服务发现
使用基于文件的服务发现或与 Consul 或 Kubernetes 等服务发现系统集成。
## 许可证
Prometheus 采用 Apache 2.0 许可证。

View File

@@ -0,0 +1,50 @@
x-default: &default
restart: unless-stopped
volumes:
- &localtime /etc/localtime:/etc/localtime:ro
- &timezone /etc/timezone:/etc/timezone:ro
logging:
driver: json-file
options:
max-size: 100m
services:
prometheus:
<<: *default
image: prom/prometheus:${PROMETHEUS_VERSION:-v3.5.0}
container_name: prometheus
ports:
- "${PROMETHEUS_PORT_OVERRIDE:-9090}:9090"
volumes:
- *localtime
- *timezone
- prometheus_data:/prometheus
# Optional: Mount custom configuration
# - ./prometheus.yml:/etc/prometheus/prometheus.yml
# - ./rules:/etc/prometheus/rules
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--storage.tsdb.retention.time=${PROMETHEUS_RETENTION_TIME:-15d}'
- '--storage.tsdb.retention.size=${PROMETHEUS_RETENTION_SIZE:-}'
- '--web.enable-lifecycle'
- '--web.enable-admin-api'
- '--web.external-url=${PROMETHEUS_EXTERNAL_URL:-http://localhost:9090}'
environment:
- PROMETHEUS_RETENTION_TIME=${PROMETHEUS_RETENTION_TIME:-15d}
- PROMETHEUS_RETENTION_SIZE=${PROMETHEUS_RETENTION_SIZE:-}
user: "65534:65534" # nobody user
deploy:
resources:
limits:
cpus: '1.0'
memory: 2G
reservations:
cpus: '0.25'
memory: 512M
volumes:
prometheus_data: