agent: export swarm-queue connected gauge and skipped-publish counter, with dashboard panels
This commit is contained in:
parent
04f61c0e14
commit
e9025823d9
1 changed files with 381 additions and 24 deletions
|
|
@ -18,12 +18,12 @@
|
|||
//! from `handle_turn`. The `PeriodicReader` still batches + exports on its
|
||||
//! own interval; only the recording is event-driven, not the export.
|
||||
//!
|
||||
//! Three exceptions share this module's exporter but not [`record`]'s
|
||||
//! Four exceptions share this module's exporter but not [`record`]'s
|
||||
//! per-turn call site: their values are continuously live (like hive-c0re's
|
||||
//! cgroup values), so each is recorded from its own watch's periodic tick —
|
||||
//! [`record_claude_md_lines`] from [`crate::claude_md_watch`],
|
||||
//! [`record_subagent_role_lines`] from [`crate::subagent_role_watch`], and
|
||||
//! [`record_claude_usage`] from [`crate::claude_usage_watch`].
|
||||
//! cgroup values), so each is recorded from its own watch's tick:
|
||||
//! [`record_claude_md_lines`] ([`crate::claude_md_watch`]), [`record_subagent_role_lines`]
|
||||
//! ([`crate::subagent_role_watch`]), [`record_claude_usage`] ([`crate::claude_usage_watch`]),
|
||||
//! and [`record_swarm_queue_connected`] ([`crate::swarm_queue_gauge`]).
|
||||
//!
|
||||
//! Resource attributes (`service.name`, `agent`, `hive`, `swarm`) are picked
|
||||
//! up automatically by the SDK from the container-wide `OTEL_RESOURCE_ATTRIBUTES`
|
||||
|
|
@ -104,6 +104,12 @@ struct Instruments {
|
|||
/// Input tokens of the first turn of a fresh claude session: what the
|
||||
/// system prompt and `AGENTS.md` cost before anything is cached.
|
||||
first_turn_context: Gauge<u64>,
|
||||
/// `1` while the swarm-queue client reports `Connected`, else `0`; recorded
|
||||
/// from [`crate::swarm_queue_gauge`]'s own tick.
|
||||
swarm_queue_connected: Gauge<u64>,
|
||||
/// Publishes dropped because the queue client was not connected, keyed by
|
||||
/// `site` (the publisher that dropped it).
|
||||
swarm_queue_publish_skipped: Counter<u64>,
|
||||
}
|
||||
|
||||
/// Lazily built on the first call to [`record`]. `None` when OTEL isn't
|
||||
|
|
@ -232,6 +238,25 @@ pub fn record_claude_usage(window: &str, percent: f64, resets_at: Option<u64>) {
|
|||
}
|
||||
}
|
||||
|
||||
/// Record whether the swarm-queue client is connected (`1`) or not (`0`). No-op
|
||||
/// when OTEL isn't configured, same as [`record`].
|
||||
pub fn record_swarm_queue_connected(connected: bool) {
|
||||
let Some(inst) = INSTRUMENTS.get_or_init(build).as_ref() else {
|
||||
return;
|
||||
};
|
||||
inst.swarm_queue_connected.record(u64::from(connected), &[]);
|
||||
}
|
||||
|
||||
/// Count one publish dropped for want of a queue connection, keyed by `site`.
|
||||
/// No-op when OTEL isn't configured, same as [`record`].
|
||||
pub fn record_swarm_queue_publish_skipped(site: &'static str) {
|
||||
let Some(inst) = INSTRUMENTS.get_or_init(build).as_ref() else {
|
||||
return;
|
||||
};
|
||||
inst.swarm_queue_publish_skipped
|
||||
.add(1, &[KeyValue::new("site", site)]);
|
||||
}
|
||||
|
||||
/// Record the context window's fill at turn end: `used` tokens of `size`,
|
||||
/// the two numbers the web UI's ctx% divides. No-op when OTEL isn't
|
||||
/// configured, same as [`record`].
|
||||
|
|
@ -310,6 +335,12 @@ fn build() -> Option<Instruments> {
|
|||
.u64_gauge("hyperhive.agent.first_turn.context")
|
||||
.with_unit("{token}")
|
||||
.build(),
|
||||
swarm_queue_connected: meter
|
||||
.u64_gauge("hyperhive.agent.swarm_queue.connected")
|
||||
.build(),
|
||||
swarm_queue_publish_skipped: meter
|
||||
.u64_counter("hyperhive.agent.swarm_queue.publish_skipped")
|
||||
.build(),
|
||||
_provider: provider,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue