跳至正文
Wener Notes

Prometheus 存储

约 3 分钟阅读
  • 主流方式
    • Remote API
    • Sidecar 上传 Chunk 做长期 + Sidecar 请求 Prometheus 查看实时
    • 分布式 TSDB,聚合查询引擎
    • Prometheus Sidecar, Graphite Compatible, Metrics Platform
  • - VictoriaMetrics - fast, cost-effective and scalable time series database, long-term remote storage for Prometheus
    • 基于 PG 的衍生数据库
      • 基于 timescaledb 实现 Prometheus 接口
    • 架构
    • Consul 中央调度、PG 配置存储、Cassandra 数据存储、S3 长期冷数据、Memcache 查询缓存
    • 设计
    • 无状态、对象存储、查询聚合去重
  • 参考

Remote

  • Prometheus Remote Storage
  • 日志
    • dropped sample for series that was not explicitly dropped via relabelling
      • 可能由于 relabel 之类的原因导致时间序列没有了 label,丢弃这类数据
    • Remote storage resharding from N to M
      • 动态队列调整分片 - 增长以保证跟上采集的指标数,写入速率
      • 如果指标数便少了也会减少
    • Currently resharding, skipping
      • 正在调整分片的时候又触发了调整
    • Failed to flush all samples on shutdown
      • 在停止一个队列时无法写入全部指标
      • 可能远程存储有问题,可能超时
  • 注意
    • rps 较大,对反向代理有一定性能影响
    • prometheus 会多用约 25% 内存
  • 参考
yaml
remote_write:
  - url: http://127.0.0.1:1234
    # 唯一远程名字 - 用于内部标示 - 会在 prometheus 指标和日志中体现
    # 不设置则会生成一个唯一的名字
    name:
    # 远程写超时 - 数据量大的时候建议设置大一点
    # 如果设置小了会导致数据一直失败
    # 如果使用了反向代理,也要注意修改反向代理的超时时间
    remote_timeout: 30s

    # 标签修改
    write_relabel_configs:
      # 移除 go_ 开头的指标
      - action: drop
        regex: go_.*
        source_labels: [__name__]

    # HTTP Authorization: Basic
    basic_auth:
      username: username
      password: password
      # 从文件读取密码
      password_file: /etc/prometheus/my-remote-password

    # HTTP Authorization: Bearer
    # 例如 JWT
    bearer_token: <string>
    bearer_token_file: /etc/prometheus/my-remote-token

    # TLS 配置
    tls_config: [<tls_config>]

    # HTTP 代理
    proxy_url: http://127.0.0.1:8080

    # 队列配置
    # 当指标量大的时候比较重要
    queue_config:
      # Number of samples to buffer per shard before we block reading of more
      # samples from the WAL. It is recommended to have enough capacity in each
      # shard to buffer several requests to keep throughput up while processing
      # occasional slow remote requests.
      # 每个 shard 的容量 - 读取 WAL 的缓冲数量
      # 超过则会扩容 - 设置过大可能会导致 OOM
      # 建议 max_samples_per_send 的 3-10 倍
      capacity: 500
      # 最小 shard 数量 - 调整最小可避免初始 rw 写入过慢
      # 如果 rw 跟不上时会增加
      min_shards: 1
      # 最大 shard 数量 - 并发数请求数
      max_shards: 1000
      # 每次批量发送的样本数 - 默认较小,为了兼容更多系统
      # 设置大可以使吞吐更大 - 压缩更好,占用更少网络
      max_samples_per_send: 100
      # 每次发送的最大等待时间 - 即便没达到 max_samples_per_send 也发送
      # 在延迟行要求不高场景可以设置高一点 - 也能增加每次发送的量
      batch_send_deadline: 5s

      # 会一直重试 - 没有最大等待次数
      # 初次重试等待
      min_backoff: 30ms
      # 最大重试等待
      max_backoff: 100ms
yaml
# 示例配置
queue_config:
  # 500
  capacity: 2500
  # 1000
  max_shards: 1000
  # 1
  min_shards: 200
  # 100
  max_samples_per_send: 5000
  # 5s
  batch_send_deadline: 10s

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

GitHub8 条
其他外链5 条
最近更新commit 0e4b1ae编辑