Add refresh shortkey 'r' for on-demand metrics refresh
Implements ZMQ command protocol for dashboard-to-agent communication: - Agents listen on port 6131 for REQ/REP commands - Dashboard sends "refresh" command when 'r' key is pressed - Agents force immediate collection of all metrics via force_refresh_all() - Fresh data is broadcast immediately to dashboard - Updated help text to show "r: Refresh all metrics" Also includes metric-level caching architecture foundation for future granular control over individual metric update frequencies.
This commit is contained in:
@@ -153,6 +153,12 @@ fn run_app(
|
||||
|
||||
while !app.should_quit() {
|
||||
drain_app_events(app, event_rx);
|
||||
|
||||
// Check for refresh requests
|
||||
if app.check_refresh_request() {
|
||||
send_refresh_commands(app)?;
|
||||
}
|
||||
|
||||
terminal.draw(|frame| ui::render(frame, app))?;
|
||||
|
||||
if event::poll(tick_rate)? {
|
||||
@@ -301,6 +307,58 @@ fn metrics_blocking_loop(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn send_refresh_commands(app: &mut App) -> Result<()> {
|
||||
let endpoints = app.zmq_endpoints();
|
||||
if endpoints.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let zmq_context = NativeZmqContext::new();
|
||||
|
||||
for endpoint in endpoints {
|
||||
// Convert metrics endpoint (6130) to command endpoint (6131)
|
||||
let command_endpoint = endpoint.replace(":6130", ":6131");
|
||||
|
||||
let socket = zmq_context.socket(zmq::REQ)?;
|
||||
socket.set_linger(0)?;
|
||||
socket.set_rcvtimeo(5000)?; // 5 second timeout
|
||||
socket.set_sndtimeo(5000)?; // 5 second timeout
|
||||
|
||||
match socket.connect(&command_endpoint) {
|
||||
Ok(()) => {
|
||||
debug!("Sending refresh command to {}", command_endpoint);
|
||||
|
||||
match socket.send("refresh", 0) {
|
||||
Ok(()) => {
|
||||
// Wait for response
|
||||
match socket.recv_string(0) {
|
||||
Ok(Ok(response)) => {
|
||||
debug!("Refresh response from {}: {}", command_endpoint, response);
|
||||
// Update status via public method would be needed, for now just log
|
||||
debug!("Refresh sent to agents - response: {}", response);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
warn!("String conversion error from {}: {:?}", command_endpoint, e);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("No response from {}: {}", command_endpoint, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to send refresh to {}: {}", command_endpoint, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to connect to command endpoint {}: {}", command_endpoint, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_zmq_message(
|
||||
message: &NativeZmqMessage,
|
||||
sender: &UnboundedSender<AppEvent>,
|
||||
|
||||
Reference in New Issue
Block a user