Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,36 @@ instance's thread count. Setting `sticky=true` suppresses automatic scaling for
that instance until a later call clears it. This debug-only override is kept in
memory and is lost when the daemon restarts.

`GetStats()` returns a JSON fleet snapshot. For example:

```json
{
"tick": 42,
"vms": [{
"vm": "vm-1",
"thread_count": 3,
"manual_scaling_sticky": false,
"scaling_allowed": true,
"vcpu_count": 8,
"per_thread_util": 0.72,
"read_io_count": 1000,
"write_io_count": 250,
"other_io_count": 0
}]
}
```

```sh
busctl --system call \
com.nutanix.io_thread_controller1 \
/com/nutanix/io_thread_controller1 \
com.nutanix.io_thread_controller1 \
GetStats
```

`GetStats` is available in release builds and world-readable under the shipped
D-Bus policy.

```sh
busctl --system call \
com.nutanix.io_thread_controller1 \
Expand Down
30 changes: 30 additions & 0 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ impl Controller {
};
let _ = reply.send(result);
}
DbusRequest::GetStats { reply } => {
let mut vms = Vec::with_capacity(self.instances.len());
for (id, instance) in &self.instances {
let status = instance.status.read().await;
let (read_io_count, write_io_count, other_io_count) = match status.perf {
Some(perf) => {
(perf.read_io_count, perf.write_io_count, perf.other_io_count)
}
None => (0, 0, 0),
};
vms.push(serde_json::json!({
"vm": id,
"thread_count": status.thread_count,
"manual_scaling_sticky": status.manual_scaling_sticky,
"scaling_allowed": status.scaling_allowed,
"vcpu_count": status.vcpu_count,
"per_thread_util": status.per_thread_util,
// FIXME omit if status.perf.is_none()?
"read_io_count": read_io_count,
"write_io_count": write_io_count,
"other_io_count": other_io_count,
}));
}
let snapshot = serde_json::json!({
"tick": self.tick_index,
"vms": vms,
})
.to_string();
let _ = reply.send(snapshot);
}
DbusRequest::AddIoThread {
vm,
id,
Expand Down
17 changes: 17 additions & 0 deletions src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//!
//! Verbs currently exposed:
//! * debug-only `SetThreadCount(vm, threads, sticky)`;
//! * read-only `GetStats()`;
//! * named-IOThread and virtqueue-mapping operations for clients that support
//! them.

Expand Down Expand Up @@ -50,6 +51,11 @@ pub enum DbusRequest {
/// Structured snapshot of every tracked instance. The reply is a JSON
/// string so the wire signature stays a bare `s` and the payload shape can
/// evolve without D-Bus IDL churn. Field contract is documented on
/// JSON snapshot of all tracked VMs.
GetStats {
/// Reply channel carrying the serialized snapshot.
reply: oneshot::Sender<String>,
},
/// [`crate::controller::SnapshotPayload`].
GetSnapshot {
/// Reply channel; JSON-encoded
Expand Down Expand Up @@ -152,6 +158,17 @@ impl Service {
Err(e) => Err(zbus::fdo::Error::Failed(e)),
}
}

/// Return the controller's machine-readable fleet snapshot.
async fn get_stats(&self) -> zbus::fdo::Result<String> {
let (tx, rx) = oneshot::channel();
self.tx
.send(DbusRequest::GetStats { reply: tx })
.await
.map_err(|_| zbus::fdo::Error::Failed("controller channel closed".into()))?;
await_with_timeout(rx).await
}

/// D-Bus wire signature: `GetSnapshot() -> s`.
///
/// The `s` return is a JSON payload matching
Expand Down
Loading