请根据下述 Prometheus 采集得到的 redis 监控指标,给出 redis 集群建议的监控告警指标,并附上对应的告警表达式 redis_active_defrag_running、redis_allocator_active_bytesredis_allocator_allocated_bytes redis_allocator_frag_bytes redis_allocator_frag_ratio redis_allocator_resident_bytes redis_allocator_rss_bytes redis_allocator_rss_ratio redis_aof_base_size_bytes redis_aof_buffer_length redis_aof_current_rewrite_duration_sec redis_aof_current_size_bytes redis_aof_delayed_fsync redis_aof_enabled redis_aof_last_bgrewrite_status redis_aof_last_cow_size_bytes redis_aof_last_rewrite_duration_sec redis_aof_last_write_status redis_aof_pending_bio_fsync redis_aof_pending_rewrite redis_aof_rewrite_buffer_length redis_aof_rewrite_in_progress redis_aof_rewrite_scheduled redis_blocked_clients redis_client_recent_max_input_buffer_bytes redis_client_recent_max_output_buffer_bytes redis_cluster_connections redis_cluster_current_epoch redis_cluster_enabled redis_cluster_known_nodes redis_cluster_messages_received_total redis_cluster_messages_sent_total redis_cluster_my_epoch redis_cluster_size redis_cluster_slots_assigned redis_cluster_slots_fail redis_cluster_slots_ok redis_cluster_slots_pfail redis_cluster_state redis_cluster_stats_messages_auth_ack_sent redis_cluster_stats_messages_auth_req_received redis_cluster_stats_messages_fail_received redis_cluster_stats_messages_fail_sent redis_cluster_stats_messages_ping_received redis_cluster_stats_messages_ping_sent redis_cluster_stats_messages_pong_received redis_cluster_stats_messages_pong_sent redis_cluster_stats_messages_update_received redis_cluster_stats_messages_update_sent redis_commands_duration_seconds_total redis_commands_processed_total redis_commands_total redis_config_io_threads redis_config_maxclients redis_config_maxmemory redis_connected_clients redis_connected_slave_lag_seconds redis_connected_slave_offset_bytes redis_connected_slaves redis_connections_received_total redis_cpu_sys_children_seconds_total redis_cpu_sys_seconds_total redis_cpu_user_children_seconds_
时间: 2025-06-18 15:16:36 浏览: 23
### 关键监控告警指标及对应 PromQL 表达式
对于 Redis 集群的高效运行,需要关注多个关键性能指标并设置合理的告警阈值。以下是基于提供的 Prometheus Redis 指标的推荐监控告警指标及其对应的 PromQL 表达式。
#### 1. **内存使用情况**
Redis 的内存管理至关重要,当内存接近上限时可能导致驱逐策略生效或写入失败。
- **告警描述**: 当 Redis 使用的内存量超过总可用内存的一定比例时触发告警。
- **PromQL 表达式**:
```promql
(rate(redis_memory_used_bytes{job="redis"}[5m]) / on(instance) group_left(node_total_memory_bytes) (node_memory_MemTotal_bytes{} * 0.8) > 1
```
该表达式计算 Redis 内存使用量占节点总内存的比例,并在超过 80% 时触发告警[^1]。
---
#### 2. **连接数过多**
高并发场景下,客户端连接数激增可能会耗尽 Redis 资源。
- **告警描述**: 如果当前建立的连接数超出预设的最大连接数,则发出警告。
- **PromQL 表达式**:
```promql
rate(redis_connected_clients{job="redis"}[5m]) > 10000
```
此处假设最大允许连接数为 10,000,可根据实际需求调整阈值[^2]。
---
#### 3. **命令执行延迟**
长时间的命令响应会显著影响应用性能。
- **告警描述**: 若某些 Redis 命令平均执行时间超过设定阈值则报警。
- **PromQL 表达式**:
```promql
histogram_quantile(0.95, sum(rate(redis_command_duration_seconds_bucket{command=~"(get|set)"}[5m])) by (le)) > 0.1
```
此表达式监测 `GET` 和 `SET` 命令的第 95 百分位延时是否大于 100ms[^3]。
---
#### 4. **Key 缓存命中率下降**
缓存未命中的次数增多表明可能存在热点 Key 或者数据分布不合理的情况。
- **告警描述**: 缓存命中率低于某个百分比时发送通知。
- **PromQL 表达式**:
```promql
(sum(rate(redis_keyspace_hits{job="redis"}[5m])) by (instance) /
(sum(rate(redis_keyspace_hits{job="redis"}[5m])) by (instance) +
sum(rate(redis_keyspace_misses{job="redis"}[5m])) by (instance)) < 0.9
```
如果命中率小于 90%,即认为存在潜在问题。
---
#### 5. **Evicted Keys 数量异常增长**
频繁驱逐 key 可能意味着内存不足或者淘汰策略不当。
- **告警描述**: Evicted keys 记录数量持续上升应引起注意。
- **PromQL 表达式**:
```promql
increase(redis_evicted_keys_total{job="redis"}[5m]) > 100
```
每五分钟内被驱逐掉的 key 总数超过 100 即视为不正常行为。
---
#### 6. **持久化错误检测**
AOF/RDB 文件同步过程中发生错误会影响数据可靠性。
- **告警描述**: 发现任何类型的持久化错误立即报告。
- **PromQL 表达式**:
```promql
changes(redis_persistence_rdb_last_bgsave_status_failure{job="redis"}[5m]) > 0 or changes(redis_persistence_aof_last_write_error_total{job="redis"}[5m]) > 0
```
---
### 结论
以上列举了几种常见的 Redis 集群监控指标以及相应的 PromQL 查询语句来帮助运维人员及时发现和解决可能出现的问题。这些规则可以根据具体业务环境进一步优化调整。
阅读全文
相关推荐


















