乐闻世界logo
搜索文章和话题

什么是 Prometheus 的 Remote Write 和 Remote Read?

2月21日 15:40

Prometheus Remote Write 和 Remote Read 机制:

Remote Write(远程写入): 将数据从 Prometheus 发送到远程存储系统。

配置示例

yaml
remote_write: - url: "http://remote-storage:9201/api/v1/write" basic_auth: username: "user" password: "pass" queue_config: capacity: 10000 max_shards: 50 min_shards: 1 max_samples_per_send: 1000 batch_send_deadline: 5s min_backoff: 30ms max_backoff: 100ms write_relabel_configs: - source_labels: [__name__] regex: 'expensive_.*' action: drop

使用场景

  • 长期数据存储
  • 跨集群数据聚合
  • 数据分析和报表
  • 备份和容灾

Remote Read(远程读取): 从远程存储系统读取数据。

配置示例

yaml
remote_read: - url: "http://remote-storage:9201/api/v1/read" read_recent: true basic_auth: username: "user" password: "pass"

使用场景

  • 查询历史数据
  • 跨数据源查询
  • 数据分析

支持的远程存储

  • Thanos
  • Cortex
  • VictoriaMetrics
  • InfluxDB
  • M3DB
  • TimescaleDB

队列配置参数

  • capacity:队列容量
  • max_shards:最大分片数
  • min_shards:最小分片数
  • max_samples_per_send:每次发送的最大样本数
  • batch_send_deadline:批量发送超时
  • min_backoff / max_backoff:退避时间

最佳实践

  1. 使用 write_relabel_configs 过滤不需要的数据
  2. 合理配置队列参数避免内存溢出
  3. 监控 Remote Write 的性能指标
  4. 使用 read_recent: true 提高查询性能
  5. 考虑数据压缩减少网络传输

监控指标

  • prometheus_remote_storage_queue_length
  • prometheus_remote_storage_failed_samples_total
  • prometheus_remote_storage_succeeded_samples_total
标签:Prometheus