Pyroscope 2.4.1 配置参数详解

Grafana Pyroscope 2.4.1 配置参数详解:参数查看与修改方式、参数总览、server/storage/target/多租户/limits 等核心组逐项改值→生效验证→还原实测,附单机与集群生产配置模板。

PyroscopePyroscopeGrafana2026/10/22

Pyroscope 2.4.1 配置参数详解

目标:掌握 Grafana Pyroscope 2.4.1 的参数查看、修改与生效验证方法,逐项理解 server/storage/target/多租户/限制等核心配置组,并给出单机与生产两套可直接落地的配置模板。文中每个参数的改值→生效验证→还原过程均在 Ubuntu 22.04 服务器实测通过(查询日期:2026-10-22)。

一、环境信息

  • 操作系统:Ubuntu 22.04.5 LTS,linux/amd64
  • 软件版本:Grafana Pyroscope 2.4.1(revision 36d558a47,go1.26.10)
  • 安装方式:官方二进制安装于 /usr/local/bin/pyroscope,systemd 托管(unit:/etc/systemd/system/pyroscope.service),deb 包安装的默认配置模板 /etc/pyroscope/config.yml 内容一致可对照
  • 主配置文件:/etc/pyroscope/config.yaml
  • 数据目录:/var/lib/pyroscope(v2 段存储结构 segments/<shard>/<tenant>/<ULID>/)
  • 默认端口:HTTP 4040、gRPC 9095、内嵌管理口 4042(admin-server,默认仅 localhost)、内嵌 Grafana 4041(默认关闭,见 5.9)
  • 配置来源参考:官方参考手册 https://grafana.com/docs/pyroscope/latest/configure-server/reference-configuration-parameters/

二、前置条件

参数实验需要一台已按《Ubuntu 22.04 安装 Pyroscope 指南》完成安装的服务器,并确认以下状态:

  1. 服务处于运行且健康状态:
systemctl is-active pyroscope
curl -s -w " [HTTP:%{http_code}]\n" http://localhost:4040/ready

实测回显:

active
ready [HTTP:200]
  1. 具备 systemd 重载与重启权限(本文所有改值实验通过 systemctl restart pyroscope 使配置生效):
systemctl is-enabled pyroscope

实测回显:

enabled
  1. 实验前的配置基线(后续所有「还原」均回到此内容):
target: all

server:
  http_listen_port: 4040
  grpc_listen_port: 9095

storage:
  backend: filesystem
  filesystem:
    dir: /var/lib/pyroscope

⚠️ 注意:改配置属于破坏性实验,改前先备份 cp /etc/pyroscope/config.yaml /etc/pyroscope/config.yaml.bak;数据目录类实验(5.2)会切换数据落盘位置,实验期间推送的数据停留在实验目录,还原后恢复原目录。

三、参数查看与修改方式

Pyroscope 的参数体系与 Grafana Loki/Mimir 同源,有三种等价的查看方式与两种修改方式,各有适用场景。

3.1 查看方式一:命令行帮助(-h 与 -help-all)

pyroscope -h 2>&1 | head -12

实测回显:

Usage of pyroscope:
  -admin-server.http-listen-address string
    	Address for the admin HTTP server. Defaults to localhost so the port is not exposed externally. Use :: or 0.0.0.0 to listen on all interfaces. (default "localhost")
  -admin-server.http-listen-port int
    	Port for the admin HTTP server (metrics, pprof, admin). (default 4042)
  -admin-server.mode value
    	Controls the admin server for metrics, pprof and admin endpoints. 'disabled': all routes on the main port (default). 'additional': admin server started, operational routes served on both ports. 'exclusive': admin server started, operational routes removed from main port. (default "disabled")

帮助末行提示 To see all flags, use -help-all——-h 只列默认注册的 flag,-help-all 会追加各模块的完整 flag 集(v2.4.1 实测全量输出约 33KB、四百余个 flag,建议 grep 按前缀过滤,例如 pyroscope -help-all 2>&1 | grep -E '^\s*-server\.' | head -5)。注意:-h 与 -help-all 不会列出全部隐藏 flag(如 min-ready 系列,见 5.8 节)。

3.2 查看方式二:配置模板(deb 包自带)

deb/apt 安装后自带的 /etc/pyroscope/config.yml 是全量注释模板,所有字段以默认值形式注释列出,是了解「YAML 层有哪些字段」的最佳参考(文件开头注明官方参考链接)。查看 server 组默认值示例:

grep -A1 'http_listen_port' /etc/pyroscope/config.yml | head -4

实测回显:

  # HTTP server listen port.
  # http_listen_port: 4040

3.3 查看方式三:服务端构建信息(确认运行版本)

配置实验前先确认实际运行版本与配置层对应:

curl -s http://localhost:4040/api/v1/status/buildinfo

实测回显:

{"status":"success","data":{"version":"2.4.1","revision":"36d558a47","branch":"HEAD","buildUser":"","buildDate":"","goVersion":"go1.26.10"}}

3.4 修改方式一:YAML 配置文件(推荐,持久化)

把 flag 转成 YAML 的规则:前缀去点分层、连字符转下划线。例如 flag -server.http-listen-port 对应:

server:
  http_listen_port: 4040

改后 systemctl restart pyroscope 生效。不是所有 flag 都有 YAML 字段(反例如 ingester.min-ready-duration,见 5.8 实录),拿不准时先用 flag 验证再找 YAML 对应。

3.5 修改方式二:命令行 flag(优先级更高,适合临时覆盖与隐藏参数)

flag 直接追加在 ExecStart 上,格式 -组名.参数名=值:

pyroscope -config.file=/etc/pyroscope/config.yaml -server.http-listen-port=4041

命令行 flag 与 YAML 同名时命令行优先。隐藏 flag(-h 不显示但可接受)必须走这条路。

💡 技术拓展:配置生效优先级对比——

层级方式特点
命令行 flagpyroscope -server.http-listen-port=4041优先级最高,覆盖同名 YAML;unit 文件里维护
YAML 配置文件-config.file 指向的文件持久化主配置,可读性最好(推荐日常用)
环境变量展开YAML 内 ${VAR} + -config.expand-env敏感值注入与多环境复用同一份配置(见 5.7 实测)

本文日常修改用 YAML,隐藏参数与敏感值用 flag / 环境变量,三者在 unit 中可混用。

四、参数总览

按功能组汇总 v2.4.1 主要参数组(默认值取自实测 -h 输出与 deb 包配置模板):

参数组(前缀)作用代表参数(默认值)
target加载哪些模块target: "all"(单机模式)
config.*配置加载行为-config.file、-config.expand-env、-config.show_banner(true)
server.*HTTP/gRPC 服务与日志http_listen_port(4040)、grpc_listen_port(9095)、log_level(info)、http_server_read_timeout(30s)、http_server_write_timeout(30s)、http_server_idle_timeout(2m)
admin_server.*管理/指标端点mode(disabled)、http_listen_port(4042)、http_listen_address(localhost)
storage.*存储后端backend(filesystem)、filesystem.dir(./data/v2/shared);prefix(对象存储路径前缀)
metastore.*v2 元数据(Raft)raft.dir(./data/v2/metastore/raft)、data_dir(./data/v2/metastore/data)
distributor.*接收与校验pushtimeout(5s)
limits.*租户级限制ingestion_rate_mb(4)、ingestion_burst_size_mb(2)、max_label_names_per_series(30)、max_profile_size_bytes(4194304)、retention_period(31d)、max_query_lookback(1w)、max_query_length(1d)、reject_older_than(1h)、reject_newer_than(10m)、max_recording_rules(25)
memberlist.*内置 gossip 一致性bind_port(7946)、join_members(空)
compactor.*[v1 存储] 块压缩blocks-retention-period(0 禁用)、data-dir
self_profiling.*服务自剖析disable_push(false)、mutex_profile_fraction(5)、block_profile_rate(5)
analytics.*匿名使用统计reporting_enabled(true)
multitenancy_enabled多租户开关false
architecture_storage存储架构层v1-v2-dual(新存储写查 + 旧数据可查)
embedded_grafana.*内嵌 Grafanalisten_port(4041)、pyroscope_url(http://localhost:4040)
pyroscopedb.*[v1 存储] 本地段库data_path(./data)、max_block_duration(1h)

关键差异解读:v2.4.1 处于存储架构换代期,storage.* 与 architecture_storage 决定走 v2 段存储(metastore/segment-writer 参与)还是 v1 块存储(ingester/compactor/pyroscopedb 参与);单机与集群的参数分界主要在 target 与 storage.backend,其余限制类参数(limits)两个形态通用。

五、核心参数分类详解

以下每个参数都按「改值 → 生效验证 → 还原」完整实测。

5.1 server 组:服务端口与 HTTP 行为

以最常用的 http_listen_port 为例,把 4040 改成 4041 验证生效链路。

改值(sed 替换后重启):

sed -i 's/http_listen_port: 4040/http_listen_port: 4041/' /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 8

生效验证(新端口应答、旧端口失联):

curl -s -w " [HTTP:%{http_code}]\n" http://localhost:4041/ready
curl -s -o /dev/null -w "4040 HTTP:%{http_code}\n" --max-time 3 http://localhost:4040/ready || echo "4040 已不通"
systemctl is-active pyroscope

实测回显:

ready [HTTP:200]
4040 HTTP:000
4040 已不通
active

还原:

sed -i 's/http_listen_port: 4041/http_listen_port: 4040/' /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 8
curl -s -w " [HTTP:%{http_code}]\n" http://localhost:4040/ready

实测回显:

ready [HTTP:200]

同组其他常用项(默认值见第四章总览):log_level(排障时临时改 debug)、http_server_*_timeout(大 profile 上传超时报错时调大 read/write 超时)、http_path_prefix(反代子路径场景)。

5.2 storage 组:数据目录切换

把数据目录改到 /var/lib/pyroscope-alt,验证服务在新目录落盘:

sed -i 's|dir: /var/lib/pyroscope$|dir: /var/lib/pyroscope-alt|' /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 8
ls /var/lib/pyroscope-alt/
curl -s -w " [HTTP:%{http_code}]\n" http://localhost:4040/ready

实测回显:

segments
ready [HTTP:200]

新目录自动生成 segments 子目录(v2 段存储结构),服务健康。这就是「改数据目录是否生效」的验证手段:新目录出现 segments/ 即生效。还原回原目录:

sed -i 's|dir: /var/lib/pyroscope-alt|dir: /var/lib/pyroscope|' /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 8

⚠️ 注意:切换目录期间旧目录数据不会迁移,v2 段的元数据(metastore)按目录指向查找数据;生产环境改存储目录前先停写、改后确认旧数据可见性,否则会出现「数据在旧目录但索引找不到」的查询空结果(本系列实测曾在多次目录切换后遇到旧段查询为空,重推数据即恢复)。

5.3 target 参数:单机与微服务模式

target 决定本进程加载哪些模块。改成单模块 distributor 观察「残缺模式」的典型报错,验证 target 的实际控制力:

sed -i 's/^target: all/target: distributor/' /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 6
curl -s http://localhost:4040/ready | head -2
curl -s -o /dev/null -w "UI HTTP:%{http_code}\n" http://localhost:4040/

实测回显:

Distributor not ready: segment-writer ring: empty ring
UI HTTP:302

解读:纯 distributor 进程没有写入后端(segment-writer ring 为空),健康检查不通过——这正说明 target 真实控制了模块装载。还原:

sed -i 's/^target: distributor/target: all/' /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 8
curl -s -w " [HTTP:%{http_code}]\n" http://localhost:4040/ready

实测回显:

ready [HTTP:200]

💡 技术拓展:target 的常见取值对比——

取值含义适用场景
all全模块单进程单机/小规模(本文默认)
distributor只跑接收分发集群写入口横向扩容
querier / query-frontend只跑查询集群查询层独立扩容
ingester只跑写入存储(v1)集群存储层
metastore / segment-writer / compaction-workerv2 写路径角色v2 集群按角色拆分

集群部署时每个节点一个 target(逗号分隔可组合),配合 memberlist/join_members 组网;单机保持 all。

5.4 multitenancy_enabled:多租户开关

追加参数开启多租户:

sed -i '/^multitenancy_enabled/d' /etc/pyroscope/config.yaml
printf '\nmultitenancy_enabled: true\n' >> /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 8

生效验证:无租户头的数据面请求应被拒、带头应放行:

FROM=$(($(date +%s)000 - 3600000)); UNTIL=$(date +%s000)
echo "--无header render--"
curl -s -w " [HTTP:%{http_code}]\n" "http://localhost:4040/pyroscope/render?query=process_cpu:cpu:nanoseconds:cpu:nanoseconds&from=$FROM&until=$UNTIL&format=json" | head -c 200
echo
echo "--带header render--"
curl -s -H "X-Scope-OrgID: tenant-a" -o /dev/null -w "HTTP:%{http_code}\n" "http://localhost:4040/pyroscope/render?query=process_cpu:cpu:nanoseconds:cpu:nanoseconds&from=$FROM&until=$UNTIL&format=json"

实测回显:

--无header render--
{"code":"unauthenticated","message":"no org id"} [HTTP:401]
--带header render--
HTTP:200

401 no org id 与带头 200 即多租户生效的铁证;同时意味着所有采集端(Alloy/SDK/profilecli)都要配 tenant_id。还原:

sed -i '/^multitenancy_enabled/d' /etc/pyroscope/config.yaml
systemctl restart pyroscope && sleep 8

5.5 limits 组:租户级限制(默认值实测)

limits 组控制摄取与查询上限,默认值直接读 deb 包配置模板(即服务端默认):

grep -E '# (ingestion_rate_mb|ingestion_burst_size_mb|max_label_names_per_series|max_profile_size_bytes|retention_period|max_query_lookback|reject_older_than|reject_newer_than|max_recording_rules):' /etc/pyroscope/config.yml

实测回显:

  # ingestion_rate_mb: 4
  # ingestion_burst_size_mb: 2
  # max_label_names_per_series: 30
  # max_profile_size_bytes: 4194304
  # retention_period: 31d
  # max_query_lookback: 1w
  # reject_older_than: 1h
  # reject_newer_than: 10m
  # max_recording_rules: 25

生产最常调的三个:

  • retention_period: 31d:数据保留期,磁盘紧张时收紧、合规要求长时放宽;改小后超期段被清理,会真实删除历史剖析数据。
  • ingestion_rate_mb: 4:每租户每秒摄取样本量上限(MB 计),全量接入大批服务时按「峰值 profile 大小 × 每秒请求数」估算上调,超限报 429。
  • max_query_lookback: 1w:查询回看上限,控制「最远能查多久之前的数据」,与 retention 配合约束冷数据访问。

limits 属于纯值域参数(改大改小不影响架构),改后重启生效即可;验证方式为超限触发对应 4xx 响应(如把 max_label_names_per_series 改为 1 后推送多标签 profile 会被 distributor 拒绝)。

5.6 server 组超时项与 admin_server

HTTP 超时三件套默认 read 30s / write 30s / idle 2m(deb 模板实测):

grep -E '# (http_server_read_timeout|http_server_write_timeout|http_server_idle_timeout):' /etc/pyroscope/config.yml

实测回显:

  # http_server_read_timeout: 30s
  # http_server_write_timeout: 30s
  # http_server_idle_timeout: 2m

大 profile 上传超时先调 http_server_read_timeout;反代后端记得同步反代侧超时。admin_server.mode 默认 disabled(metrics/pprof/admin 都在主端口 4040),改 exclusive 会把运维端点挪到独立 4042 便于防火墙管控——单机部署保持默认即可。

5.7 -config.expand-env:环境变量展开

配置文件里写 ${PYRO_DIR},unit 注入环境变量并开 -config.expand-env,验证值被真实展开。

改配置与 unit:

sed -i 's|dir: /var/lib/pyroscope$|dir: ${PYRO_DIR}|' /etc/pyroscope/config.yaml
sed -i 's|ExecStart=/usr/local/bin/pyroscope|ExecStart=/usr/local/bin/pyroscope -config.expand-env|' /etc/systemd/system/pyroscope.service
printf 'Environment=PYRO_DIR=/var/lib/pyroscope\n' >> /etc/systemd/system/pyroscope.service
systemctl daemon-reload && systemctl restart pyroscope && sleep 8
curl -s -w " [HTTP:%{http_code}]\n" http://localhost:4040/ready

实测回显:

ready [HTTP:200]

ready 说明 ${PYRO_DIR} 已被展开为真实目录(未开 expand-env 时 ${...} 字面量会解析失败或落错目录)。同法可注入敏感值(对象存储 AK/SK)。还原:

sed -i 's|dir: ${PYRO_DIR}|dir: /var/lib/pyroscope|' /etc/pyroscope/config.yaml
sed -i 's| -config.expand-env||' /etc/systemd/system/pyroscope.service
sed -i '/^Environment=PYRO_DIR/d' /etc/systemd/system/pyroscope.service
systemctl daemon-reload && systemctl restart pyroscope && sleep 8

5.8 隐藏 flag:min-ready-duration 三兄弟(排障实录沉淀)

单机部署最常踩的参数坑:启动后 /ready 持续 503 半分多钟。实测三轮 503 文案:

Metastore not ready: 14.999999926s before reporting readiness (the wait slows rolling updates so the rest of the cluster can pick up this instance; set -metastore.min-ready-duration=0 to disable it, which is safe for local or single-instance setups)
Ingester not ready: waiting for 15s after being ready (...)
Segment Writer not ready: waiting for 30s after being ready (...)

按提示把驼峰字段写进 YAML 会失败(field min_ready_duration not found in type ingester.Config——metastore 组有同名 YAML 字段而 ingester 组没有),正确做法是命令行 flag,且实测 -store-gateway.min-ready-duration、-query-frontend.min-ready-duration 报 flag provided but not defined(不存在,别加)。最终 unit 参数:

ExecStart=/usr/local/bin/pyroscope -config.file=/etc/pyroscope/config.yaml -metastore.min-ready-duration=0 -ingester.min-ready-duration=0 -segment-writer.min-ready-duration=0

重启后验证(实测):

systemctl restart pyroscope && sleep 8
systemctl is-active pyroscope
curl -s -w " [HTTP:%{http_code}]\n" http://localhost:4040/ready

实测回显:

active
ready [HTTP:200]

另一组易混参数:-config.show_banner=false 关闭启动 banner(实测关闭后 journalctl -u pyroscope -n 60 | grep -cE '___|\\\\' 输出 0,默认 true 打印 ASCII 大字 logo)。

5.9 其他值得知道的参数组

  • self_profiling.*:服务端对自己持续剖析(service_name="pyroscope" 的 CPU/内存/goroutine 系列常驻,实测 query series 可见)。不想采集自己设 disable_push: true。
  • analytics.reporting_enabled:匿名使用统计上报,离线/合规环境设 false。
  • embedded_grafana.*:v2 内嵌了一个迷你 Grafana(默认端口 4041,默认未启用);开启后无需外接 Grafana 即可查火焰图,小规模场景可用。注意它与 server.http_listen_port 无关,改主端口不必动它。
  • memberlist.*:集群 gossip 端口 7946 与 join_members;单机留空即可。
  • storage.prefix:对象存储路径前缀,多套环境共用桶时隔离目录。

六、生产配置模板

6.1 单机模板(8GB 内存 / SSD / 中小团队全量接入)

target: all

server:
  http_listen_port: 4040
  grpc_listen_port: 9095
  log_level: info

storage:
  backend: filesystem
  filesystem:
    dir: /var/lib/pyroscope

limits:
  ingestion_rate_mb: 16
  ingestion_burst_size_mb: 8
  retention_period: 31d

multitenancy_enabled: false

analytics:
  reporting_enabled: false

self_profiling:
  disable_push: false

配套 systemd 命令行参数(隐藏 min-ready 置 0):

ExecStart=/usr/local/bin/pyroscope -config.file=/etc/pyroscope/config.yaml -metastore.min-ready-duration=0 -ingester.min-ready-duration=0 -segment-writer.min-ready-duration=0

适用说明:磁盘按「10 个服务常驻剖析 ≈ 每天 1~3GB」预估并靠 retention_period 收口;摄取限制按整机带宽放宽到 16MB/s。

6.2 集群生产模板(S3 对象存储 / 多租户 / 公司级接入,节选核心差异段)

multitenancy_enabled: true

storage:
  backend: s3
  prefix: pyroscope-prod
  s3:
    endpoint: s3.amazonaws.com
    region: ap-southeast-1
    bucket_name: my-profiles-bucket
    access_key_id: ${S3_AK}
    secret_access_key: ${S3_SK}

memberlist:
  join_members: ["pyroscope-01:7946", "pyroscope-02:7946", "pyroscope-03:7946"]

limits:
  retention_period: 90d
  ingestion_rate_mb: 64

适用说明:${S3_AK}/${S3_SK} 经 -config.expand-env 注入(不要明文进配置库);集群各节点按角色拆 target;多租户后所有采集端必须带 X-Scope-OrgID(5.4 已实测 401/200 行为)。

七、常见问题

Q1:改了配置重启后不生效?

按顺序排查:① systemctl status pyroscope 确认真重启了(Restart=on-failure 下启动失败会反复拉起旧态);② unit 的 ExecStart 里命令行 flag 覆盖了 YAML 同名值(命令行优先);③ 改的是 deb 包的 /etc/pyroscope/config.yml 而 unit 实际读的是另一个路径——以 systemctl cat pyroscope 输出的 -config.file 指向为准。

Q2:配置文件写错服务起不来,如何快速定位?

报错自带行号与字段类型(如 line 10: field filesystem not found in type main.mainFlags),按行号改;临时把 flag 直接加到 ExecStart 验证参数本身有效,再找 YAML 对应字段。日志查看:journalctl -u pyroscope --no-pager -n 30。

Q3:-h 里找不到某 flag,但报错提示它存在?

v2.4.1 存在隐藏 flag(min-ready 系列、部分 dskit 参数),-h/-help-all 都不列出;以服务运行时报错文案里的 flag 名为准直接使用(5.8 实测可用)。反向教训是别照 -h 猜 flag 名——-store-gateway.min-ready-duration、-query-frontend.min-ready-duration 实测报 flag provided but not defined。

Q4:开了多租户后 UI 打不开数据 / 采集端全部失败?

多租户要求所有读写请求带 X-Scope-OrgID(5.4 实测 401)。浏览器 UI 需经带头的代理访问,或暂时关闭该开关;采集端(Alloy/SDK/profilecli)分别配置 tenant_id。临时验证可用 curl 带头请求确认服务本身健康。

Q5:数据目录改错了,旧数据还找得到吗?

数据按 storage.filesystem.dir 指向落盘,改回原目录并重启即恢复可见(目录内容未删的情况下);集群对象存储同理改 bucket_name/prefix 指回即可。切勿在指向错误目录时反复推数据——新目录会生成新段,回切后查询时间线会出现空洞。

八、参考链接