了解如何为 Piglet Run 实例设置告警和监控。
概述
Piglet Run 包含全面的监控功能:
- Grafana 仪表盘:可视化监控
- 告警:可配置的告警
- 指标:基于 Prometheus 的指标
- 日志:集中式日志
快速设置
访问监控仪表盘:
pig monitor open
# 在 http://<ip>/ui 打开 Grafana
Grafana 仪表盘
可用仪表盘
访问仪表盘
# 默认凭据
URL: http://<ip>/ui
用户: admin
密码: (安装时显示)
设置告警
启用邮件告警
pig alert email --to admin@example.com --smtp smtp.example.com
启用 Slack 告警
pig alert slack --webhook https://hooks.slack.com/services/...
启用 Webhook 告警
pig alert webhook --url https://api.example.com/alerts
告警规则
查看告警规则
添加自定义告警
pig alert add \
--name "High CPU" \
--condition "cpu_usage > 80" \
--duration 5m \
--severity warning
默认告警
配置
/etc/piglet/alerts.yml 中的告警配置:
alerts:
email:
enabled: true
to: admin@example.com
smtp:
host: smtp.example.com
port: 587
slack:
enabled: false
webhook: ""
rules:
- name: high_cpu
expr: cpu_usage > 80
for: 5m
severity: warning
查看日志
# 所有服务日志
pig logs
# 特定服务
pig logs postgres
pig logs nginx
下一步