Austin消息监控:实时监控大盘与告警
1. 消息推送平台监控痛点与解决方案
在消息推送平台(Message Push Platform)的日常运营中,运维与开发团队常面临三大核心痛点:
- 链路黑盒:消息从创建到下发的全流程状态不可见,故障排查需逐节点日志检索
- 指标割裂:各渠道(短信/邮件/推送)监控数据分散,缺乏统一视图
- 告警滞后:异常发生后依赖用户反馈,无法实时感知服务健康状态
Austin平台通过整合Prometheus监控系统(普罗米修斯监控系统)、Grafana可视化面板(图形化度量分析与监控平台) 和Graylog分布式日志,构建了覆盖"实时监控-异常告警-故障定位"的完整解决方案。系统架构采用分层设计:
2. 监控体系核心组件部署
2.1 基础环境准备
通过Docker Compose一键部署监控基础设施,关键配置如下:
version: '2'
networks:
monitor:
driver: bridge
services:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
- monitor
grafana:
image: grafana/grafana
ports:
- "3000:3000"
networks:
- monitor
graylog:
image: graylog/graylog:4.2
environment:
- GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9009/
- GRAYLOG_ROOT_TIMEZONE=Asia/Shanghai
ports:
- "9009:9000"
- "12201:12201/udp"
networks:
- monitor
2.2 应用监控接入
在Austin应用中添加Actuator依赖,暴露Prometheus指标端点:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
配置application.properties:
management.endpoints.web.exposure.include=prometheus,health,info
management.metrics.tags.application=austin
Prometheus采集配置(prometheus.yml):
scrape_configs:
- job_name: 'austin'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['127.0.0.1:8888']
3. 核心监控指标体系
Austin监控指标分为业务指标与系统指标两大类,通过自定义Metric实现精细化监控:
3.1 业务核心指标
| 指标名称 | 类型 | 说明 | 告警阈值 |
|---|---|---|---|
| austin_message_total | Counter | 消息总发送量 | - |
| austin_message_success_rate | Gauge | 消息成功率 | <99% |
| austin_channel_delay_seconds | Summary | 渠道响应延迟 | P95>1s |
| austin_deduplication_count | Counter | 去重拦截量 | - |
| austin_shield_count | Counter | 夜间屏蔽量 | - |
关键指标实现代码:
// 消息发送计数器
private static final Counter MESSAGE_COUNTER = Metrics.counter("austin_message_total",
"channel", "sms", "templateId", "10001");
// 响应时间计时器
private static final Timer RESPONSE_TIMER = Metrics.timer("austin_channel_response_time",
"provider", "aliyun");
public void sendSms(String phone, String content) {
Timer.Sample sample = Timer.start(Metrics.globalRegistry);
try {
// 发送逻辑
MESSAGE_COUNTER.increment();
} finally {
sample.stop(RESPONSE_TIMER);
}
}
3.2 系统资源指标
通过Spring Boot Actuator自动暴露JVM与容器指标:
- JVM内存使用(jvm_memory_used_bytes)
- 线程池活跃数(executor.active.threads)
- 数据库连接池(hikaricp_connections_active)
- Redis命令执行耗时(redis.command.duration)
4. Grafana可视化大盘
4.1 多维度监控视图
通过Grafana模板ID导入预设面板:
- JVM监控:模板ID
4701 - 容器监控:模板ID
893 - 业务大盘:自定义JSON面板
核心监控视图包含四个模块:
4.2 自定义业务面板
SQL查询示例(消息成功率趋势):
sum(increase(austin_message_success_total[5m]))
/
sum(increase(austin_message_total[5m]))
* 100
面板配置关键参数:
- 时间范围:默认24小时,支持1小时/7天切换
- 刷新频率:10秒自动刷新
- 阈值线:成功率99%红色警戒线
- 下钻功能:点击异常点跳转至Graylog日志
5. 告警策略与日志定位
5.1 多级告警规则
基于Prometheus AlertManager配置告警规则:
groups:
- name: austin_alerts
rules:
- alert: MessageSuccessRateDrop
expr: sum(rate(austin_message_success_total[5m])) / sum(rate(austin_message_total[5m])) < 0.99
for: 2m
labels:
severity: critical
annotations:
summary: "消息成功率下降"
description: "成功率={{ $value | humanizePercentage }} (阈值:99%)"
告警级别定义:
- P0(紧急):核心渠道中断,影响>50%用户
- P1(重要):成功率<95%或延迟>3s
- P2(一般):单渠道波动,成功率>95%
- P3(提示):系统资源使用率偏高
5.2 分布式日志追踪
Graylog日志采集配置:
- 添加GELF UDP输入(端口12201)
- 应用集成logback-gelf依赖
- 配置logback-spring.xml:
<appender name="GELF" class="de.siegmar.logbackgelf.GelfUdpAppender">
<graylogHost>127.0.0.1</graylogHost>
<graylogPort>12201</graylogPort>
<includeRawMessage>false</includeRawMessage>
<additionalField>application=austin</additionalField>
<additionalField>environment=prod</additionalField>
</appender>
日志检索实战:
- 按业务ID查询:
businessId: "2023101210001" - 按错误类型过滤:
level: ERROR AND logger_name: "com.java3y.austin.handler.action.SendMessageAction" - 渠道超时分析:
message: "channel timeout" AND channel: "getui"
6. 部署与最佳实践
6.1 容器化部署流程
# 1. 部署基础设施
git clone https://gitcode.com/GitHub_Trending/au/austin
cd austin/doc/docker
docker-compose up -d prometheus grafana graylog
# 2. 配置Grafana数据源
curl -X POST -H "Content-Type: application/json" -d @datasource.json http://admin:admin@localhost:3000/api/datasources
# 3. 导入监控面板
curl -X POST -H "Content-Type: application/json" -d @dashboard.json http://admin:admin@localhost:3000/api/dashboards/db
6.2 监控优化建议
-
指标采样优化:
// 高频指标降低采样率 MeterRegistry registry = Metrics.globalRegistry; if (registry.config().meterFilter(MeterFilter.deny(id -> id.getName().startsWith("austin.debug") && !id.getTag("env").equals("test")))) { // 生产环境禁用调试指标 } -
日志脱敏处理:
// LogUtils.java中实现敏感信息脱敏 public static String maskPhone(String phone) { if (phone == null) return null; return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); } -
告警抑制规则:
# AlertManager配置避免告警风暴 inhibit_rules: - source_match: severity: 'critical' target_match: severity: 'warning' equal: ['alertname', 'instance']
7. 故障案例与排查流程
7.1 典型故障案例分析
案例1:短信渠道响应延迟
- 现象:Grafana中
sms_channel_delay_secondsP95突增至3秒 - 定位:Graylog查询
channel:sms AND response_time:>3000 - 根因:运营商API限流,返回429 Too Many Requests
- 解决:动态调整线程池参数,启用备用渠道
案例2:消息成功率骤降
- 现象:
message_success_rate从99.8%降至85% - 定位:Prometheus查看各渠道成功率,发现push渠道异常
- 日志:Graylog检索
channel:push AND result:fail - 解决:更新厂商SDK,修复Token过期问题
7.2 标准化排查流程
8. 监控系统演进方向
Austin监控体系将持续优化三个方向:
- 智能化监控:引入机器学习算法,实现异常检测与根因分析
- 全链路追踪:集成SkyWalking,实现从API到渠道的分布式追踪
- 监控自愈:通过Apollo配置中心实现自动扩缩容与故障转移
通过docker-compose一键部署完整监控栈,30分钟即可完成从环境搭建到告警配置的全流程,让消息推送平台的运营更可控、更稳定。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



