菜单
开源

sampling

注意

Promtail 已被弃用,并将长期支持 (LTS) 至 2026 年 2 月 28 日。Promtail 将于 2026 年 3 月 2 日终止生命周期 (EOL)。您可以在此处找到迁移资源。

sampling 阶段是一个用于对日志进行采样的阶段。

Sampling 阶段模式

sampling 阶段用于对日志进行采样。将值配置为 rate: 0.1 意味着将有 10% 的日志推送到 Loki 服务器。

yaml
sampling:
  # The rate sampling in lines per second that Promtail will push to Loki.The value is between 0 and 1, where a value of 0 means no logs are sampled and a value of 1 means 100% of logs are sampled.
  [rate: <int>]  

示例

以下示例展示了 sampling 阶段的使用。

sampling

简单采样

给定管道

yaml
- sampling:
    rate: 0.1

匹配一行并采样

给定管道

yaml
pipeline_stages:
- json:
    expressions:
      app:
- match:
    pipeline_name: "app2"
    selector: '{app="poki"}'
    stages:
    - sampling:
        rate: 0.1

复杂的 sampling 阶段配置。