乐于分享
好东西不私藏

OpenClaw 指标监控实践

OpenClaw 指标监控实践
本文整理 OpenClaw 接入 OpenTelemetry 进行指标监控的完整方案,包括内置指标说明。

一、OpenClaw OTel 监控概述

OpenClaw 通过内置的 diagnostics-otel 插件支持 OpenTelemetry,覆盖 Traces / Metrics / Logs 三类遥测数据。

协议限制:

  • 仅支持 http/protobuf,不支持 gRPC
  • endpoint 会自动追加 /v1/traces/v1/metrics/v1/logs

二、OpenClaw 内置指标(Metrics)

指标名
类型
说明
openclaw.tokens
counter
Token 用量(含 input/output 属性)
openclaw.cost.usd
counter
API 费用(美元)
openclaw.run.duration_ms
histogram
单次运行耗时
openclaw.context.tokens
histogram
上下文 token 数
openclaw.webhook.received
counter
收到的 webhook 数
openclaw.webhook.error
counter
webhook 处理错误数
openclaw.webhook.duration_ms
histogram
webhook 处理耗时
openclaw.message.queued
counter
入队消息数
openclaw.message.processed
counter
已处理消息数
openclaw.message.duration_ms
histogram
消息处理耗时
openclaw.queue.depth
histogram
队列深度
openclaw.queue.wait_ms
histogram
消息队列等待时间
openclaw.session.state
counter
会话状态变更
openclaw.session.stuck
counter
会话卡住次数
openclaw.run.attempt
counter
运行重试次数

注意:openclaw.tokens 是 Metric 名称,通过属性 openclaw.token=input/output 区分输入输出 token,而非独立指标名。


三、OpenClaw 内置 Trace Spans

Span 名
关键属性
openclaw.model.usage
channel、provider、model、sessionKey/Id、token 明细
openclaw.webhook.processed
channel、webhook、chatId
openclaw.webhook.error
channel、webhook、chatId
openclaw.message.processed
channel、outcome、chatId、messageId
openclaw.session.stuck
state、ageMs、queueDepth

四、参考资料

  • OpenClaw 官方文档:https://docs.openclaw.ai/
  • SigNoz 文档:https://signoz.io/docs/
  • OpenTelemetry 规范:https://opentelemetry.io/docs/