[ PROMPT_NODE_25156 ]
prometheus-configuration
[ SKILL_DOCUMENTATION ]
# Prometheus 配置
Prometheus 设置、指标收集、抓取配置和记录规则的完整指南。
## 请勿在以下情况使用此技能
- 任务与 Prometheus 配置无关
- 需要此范围之外的其他领域或工具
## 指令
- 明确目标、约束和所需输入。
- 应用相关的最佳实践并验证结果。
- 提供可操作的步骤和验证方法。
- 如果需要详细示例,请打开 `resources/implementation-playbook.md`。
## 目的
配置 Prometheus 以实现对基础设施和应用程序的全面指标收集、告警和监控。
## 何时使用此技能
- 设置 Prometheus 监控
- 配置指标抓取
- 创建记录规则
- 设计告警规则
- 实现服务发现
## Prometheus 架构
┌──────────────┐
│ 应用程序 │ ← 使用客户端库进行埋点
└──────┬───────┘
│ /metrics 端点
↓
┌──────────────┐
│ Prometheus │ ← 定期抓取指标
│ 服务器 │
└──────┬───────┘
│
├─→ AlertManager (告警)
├─→ Grafana (可视化)
└─→ 长期存储 (Thanos/Cortex)
## 安装
### 使用 Helm 的 Kubernetes
bash
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack
--namespace monitoring
--create-namespace
--set prometheus.prometheusSpec.retention=30d
--set prometheus.prometheusSpec.storageVolumeSize=50Gi
### Docker Compose
yaml
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=30d'
volumes:
prometheus-data:
## 配置文件
**prometheus.yml:**
yaml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
cluster: 'production'
region: 'us-west-2'
# Alertmanager 配置
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
# 加载规则文件
rule_files:
- /etc/prometheus/rules/*.yml
# 抓取配置
scrape_configs:
# Prometheus 本身
- job_name: 'prometheus'
static_configs:
- targets: