Compare commits
4 commits
931d4b26e7
...
bded8d789f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bded8d789f | ||
|
|
86a499eeb5 | ||
|
|
96d35786a5 | ||
|
|
f17ee5659e |
1 changed files with 45 additions and 2 deletions
|
|
@ -221,11 +221,20 @@ struct StatsQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn api_stats(
|
async fn api_stats(
|
||||||
State(_state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
axum::extract::Query(q): axum::extract::Query<StatsQuery>,
|
axum::extract::Query(q): axum::extract::Query<StatsQuery>,
|
||||||
) -> axum::Json<crate::stats::Snapshot> {
|
) -> axum::Json<crate::stats::Snapshot> {
|
||||||
let window = crate::stats::Window::parse(q.window.as_deref().unwrap_or("24h"));
|
let window = crate::stats::Window::parse(q.window.as_deref().unwrap_or("24h"));
|
||||||
axum::Json(crate::stats::snapshot_default(window))
|
let mut snapshot = crate::stats::snapshot_default(window);
|
||||||
|
// Fetch reminder stats from the broker. The window spans are:
|
||||||
|
// 24h = 86400s, 7d = 604800s, 30d = 2592000s.
|
||||||
|
let window_secs = match window {
|
||||||
|
crate::stats::Window::Day => 24 * 3600,
|
||||||
|
crate::stats::Window::Week => 7 * 24 * 3600,
|
||||||
|
crate::stats::Window::Month => 30 * 24 * 3600,
|
||||||
|
};
|
||||||
|
snapshot.reminder_stats = fetch_reminder_stats(&state.socket, state.flavor(), window_secs as u64).await;
|
||||||
|
axum::Json(snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|
@ -392,6 +401,40 @@ async fn recent_inbox(socket: &std::path::Path, flavor: Flavor) -> Vec<hive_sh4r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetch reminder activity stats from the broker via the per-agent /
|
||||||
|
/// manager socket. Returns None on any transport / decode failure — the
|
||||||
|
/// stats are decorative, not authoritative.
|
||||||
|
async fn fetch_reminder_stats(socket: &std::path::Path, flavor: Flavor, window_secs: u64) -> Option<hive_sh4re::ReminderStats> {
|
||||||
|
match flavor {
|
||||||
|
Flavor::Agent => {
|
||||||
|
match client::request::<_, hive_sh4re::AgentResponse>(
|
||||||
|
socket,
|
||||||
|
&hive_sh4re::AgentRequest::ReminderRollup {
|
||||||
|
since_secs: window_secs,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(hive_sh4re::AgentResponse::ReminderRollup(stats)) => Some(stats),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Flavor::Manager => {
|
||||||
|
match client::request::<_, hive_sh4re::ManagerResponse>(
|
||||||
|
socket,
|
||||||
|
&hive_sh4re::ManagerRequest::ReminderRollup {
|
||||||
|
since_secs: window_secs,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(hive_sh4re::ManagerResponse::ReminderRollup(stats)) => Some(stats),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Action handlers
|
// Action handlers
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue