MetricsRecorder
public final class MetricsRecorder
源码Source
io/agentscope/spring/boot/admin/metrics/MetricsRecorder.java:30–100指标记录器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.spring.boot.admin.metrics 包。核心成员包括 record、globalSnapshot、snapshotByAgent、snapshotByModel、reset。
Thread-safe accumulator for token usage counters, sliced by agent name and by model name.
Uses LongAdder so high-concurrency tool/model call paths don't contend on a single
AtomicLong. Snapshots are read-side: every read recomputes a frozen UsageStats.
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void record(String agentName, String modelName, int inputTokens, int outputTokens) | 执行记录相关操作。 Performs the record operation. |
public UsageStats globalSnapshot() | 返回 `globalSnapshot` 结果。 Returns the global snapshot. |
public Map<String, UsageStats> snapshotByAgent() | 返回快照通过智能体。 Returns the snapshot by agent. |
public Map<String, UsageStats> snapshotByModel() | 返回快照通过模型。 Returns the snapshot by model. |
public void reset() | 清空或重置内部状态。 Test-only — drop all counters. |
方法详情Method Detail
record
public void record(String agentName, String modelName, int inputTokens, int outputTokens)
执行记录相关操作。
Performs the record operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentName | String | 智能体名称(类型 `String`)。The agent name. |
modelName | String | 模型名称(类型 `String`)。The model name. |
inputTokens | int | 输入令牌数(类型 `int`)。The input tokens. |
outputTokens | int | 输出令牌数(类型 `int`)。The output tokens. |
源码Source
io/agentscope/spring/boot/admin/metrics/MetricsRecorder.java:36–47globalSnapshot
public UsageStats globalSnapshot()
返回 globalSnapshot 结果。
Returns the global snapshot.
UsageStats返回UsageStats。Returns usage stats.
源码Source
io/agentscope/spring/boot/admin/metrics/MetricsRecorder.java:49–51snapshotByAgent
public Map<String, UsageStats> snapshotByAgent()
返回快照通过智能体。
Returns the snapshot by agent.
Map<String, UsageStats>返回映射。Returns map.
源码Source
io/agentscope/spring/boot/admin/metrics/MetricsRecorder.java:53–55snapshotByModel
public Map<String, UsageStats> snapshotByModel()
返回快照通过模型。
Returns the snapshot by model.
Map<String, UsageStats>返回映射。Returns map.
源码Source
io/agentscope/spring/boot/admin/metrics/MetricsRecorder.java:57–59reset
public void reset()
清空或重置内部状态。
Test-only — drop all counters.
源码Source
io/agentscope/spring/boot/admin/metrics/MetricsRecorder.java:62–66