其他
无法改代码或重编译应用时,用 Grafana Beyla…
需要对闭源、遗留或无法重启的服务快速增加可观测性时,Beyla 通过 eBPF 自动插桩并导出 OTLP traces + Prometheus metrics。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 57/100 ×0.15
适用场景
无法改代码或重编译应用时,用 Grafa特定
解决思路
- 检查前提:Linux kernel 5.8+ 且 BTF 已启用,执行 `ls /sys/kernel/btf/vmlinux` 必须存在。
- 准备权限:使用 root 或 `CAP_SYS_ADMIN`;在 Kubernetes 中使用 `privileged: true` 并设置 `hostPID: true`。
- 准备架构:确认运行在 x86_64 或 ARM64。
- 准备 OTLP receiver:确保 Tempo、Alloy 或 OTel Collector 等 OTLP receiver 可从 Beyla 访问。
- 对单个二进制用 Docker 插桩:先让应用已运行并监听 `8080`;运行 `docker run --privileged --pid=host -v /sys/kernel/debug:/sys/kernel/debug:ro -e BEYLA_OPEN_PORT=8080 -e BEYLA_PROMETHEUS_PORT=8999 -e OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 -p 8999:8999 grafana/beyla`。
- 生成流量验证:执行 `curl http://localhost:8080/ ; curl http://localhost:8080/api/users/42`。
- 验证 Beyla 是否发出指标:执行 `curl -s http://localhost:8999/metrics | grep -E '^http_(server|client)_request_duration'`,应列出 `http_server_request_duration_seconds` 和 counters。
- 验证 traces:在 Grafana Explore 的 Tempo 中按 `service.name`(默认等于 process name)搜索;或查询 Tempo search API 查找 `service.name="<app>"` 的 spans。
- 部署为集群级 DaemonSet:完整 DaemonSet + RBAC YAML 位于 `references/kubernetes.md`;应用后继续验证。
- 验证 DaemonSet rollout:`kubectl -n monitoring rollout status ds/beyla`。
- 验证 pods 为 Running 且每节点一个:`kubectl -n monitoring get pods -l app=beyla -o wide`。
- 验证 eBPF probes 已附着:`kubectl -n monitoring logs ds/beyla --tail=50 | grep -Ei 'error|fail|btf' || echo "clean"`,不应出现 BTF 或 permission denied 错误。
- 验证 telemetry 正在流动:检查 Tempo/Alloy receiver 是否有来自集群的 spans;或直接 scrape 一个 pod:`kubectl -n monitoring port-forward ds/beyla 8999:8999 & curl -s localhost:8999/metrics | head`。
- 通过 Alloy 发送到 Grafana Cloud:在 `beyla-config.yml` 中设置 `otel_traces_export: { endpoint: http://alloy:4318 }` 和 `otel_metrics_export: { endpoint: http://alloy:4318 }`。
- 验证 Alloy 转发:检查 Alloy UI(`localhost:12345`)中 `otelcol.receiver.otlp.beyla` 组件的 received spans/metrics 大于 0。
- 查阅完整 Alloy + Beyla YAML:`references/config.md`。
- 排障 `failed to load BPF object`:检查 kernel < 5.8 或 BTF 缺失;检查 `/sys/kernel/btf/vmlinux`。
- 排障 Tempo 无 spans 但 Prometheus metrics 有数据:检查 `OTEL_EXPORTER_OTLP_ENDPOINT`、协议(http vs grpc)和端口(4318 http / 4317 grpc)。
- 排障 HTTP route cardinality 爆炸:设置 `routes.unmatched: heuristic` 并添加 patterns(见 `references/config.md`)。
- 排障 Pod 重启 `CrashLoopBackOff`:通常缺少 `hostPID: true` 或 `privileged: true` / 所需 capabilities。
- 资源:查阅 Beyla docs `https://grafana.com/docs/beyla/latest/` 和 Beyla GitHub `https://github.com/grafana/beyla`。
- 资源:`references/config.md` 包含完整 config、env vars、samplers、routes decorator、generated metrics table、runtime matrix。
- 资源:`references/kubernetes.md` 包含 DaemonSet + RBAC + discovery filters + Helm。
- 覆盖能力:支持 Go / Java / Python / Ruby / Node / .NET / Rust / C++ / PHP 等语言,无需按语言改代码即可自动插桩。
- 使用端口发现:设置 `BEYLA_OPEN_PORT=8080` 指定要插桩的监听端口。
- 使用进程发现:按进程名或属性匹配目标进程,完整配置见 `references/config.md`。
- 使用 Kubernetes-metadata discovery:在 DaemonSet 中启用 Kubernetes metadata discovery 过滤器,完整配置见 `references/kubernetes.md`。
- 导出 OTLP traces:设置 `OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318` 或 `otel_traces_export.endpoint`。
- 导出 Prometheus metrics:设置 `BEYLA_PROMETHEUS_PORT=8999` 或 `otel_metrics_export.endpoint`。
- 控制 route cardinality:配置 routes decorator,设置 `routes.unmatched: heuristic` 并添加 patterns。
- 配置 trace sampling:使用 samplers,完整配置见 `references/config.md`。
适用边界 · 注意事项
- Linux 内核低于 5.8、未启用 BTF,或无法提供 root/CAP_SYS_ADMIN(K8s 中为 privileged: true + hostPID: true)时不要用。
- 运行平台不是 x86_64 或 ARM64 时不要用。
- 没有 Beyla 可访问的 OTLP receiver(Tempo、Alloy、OTel Collector)时不要用。