Skip to content
Merged

util #29

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
227 changes: 226 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ instability = "=0.3.10"

# Only for the TUI:
anyhow = "1.0.104"
statistical = "1.0.0"

[dev-dependencies]
tempfile = "=3.14.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ occupies one line.

```
INFO vm=vm-a thr=4 iops=155593/0/0 bw_mb_s=20394/0 \
cpu=90/358 iops_1_5_15m=154995/153840/151220 \
cpu=90/87/358 iops_1_5_15m=154995/153840/151220 \
cpu_us_per_io_1_5_15m=23/16/19
```

Expand All @@ -154,7 +154,7 @@ INFO vm=vm-a thr=4 iops=155593/0/0 bw_mb_s=20394/0 \
- `iops`: current read / write / other operations per second.
- `iops_1_5_15m`: average total IOPS over rolling 1m / 5m / 15m windows.
- `bw_mb_s`: current read / write bandwidth in MB/s.
- `cpu`: average per-thread / total pool CPU percentage.
- `cpu`: average / median / total worker CPU percentage.
- `cpu_us_per_io_1_5_15m`: CPU microseconds per completed I/O over the same
windows.

Expand Down
16 changes: 13 additions & 3 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
use futures_util::future::join_all;
use procfs::{CurrentSI, ProcError};
use serde::{Deserialize, Serialize};
use statistical::median;
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -122,6 +123,16 @@ struct CpuStats {

/// Summarise per-worker utilisation, falling back to aggregate samples.
fn compute_cpu_stats(s: &crate::instance::InstanceStatus) -> CpuStats {
if !s.per_worker_util.is_empty() {
let total = s.per_worker_util.iter().sum::<f64>();
let median = median(&s.per_worker_util);
return CpuStats {
avg_pct: (total / s.per_worker_util.len() as f64 * 100.0).round() as u64,
median_pct: (median * 100.0).round() as u64,
total_pct: (total * 100.0).round() as u64,
};
}

CpuStats {
avg_pct: (s.per_thread_util * 100.0).round() as u64,
median_pct: (s.per_thread_util * 100.0).round() as u64,
Expand Down Expand Up @@ -730,8 +741,7 @@ impl Controller {
status: &InstanceStatus,
iops_windows: [Option<u64>; 3],
) {
let cpu_average = status.per_thread_util.clamp(0.0, 1.0) * 100.0;
let cpu_total = cpu_average * f64::from(status.thread_count);
let cpu = compute_cpu_stats(status);
tracing::info!(
target: "status",
vm = instance.to_string(),
Expand All @@ -748,7 +758,7 @@ impl Controller {
status.read_bytes_per_second / 1_000_000,
status.write_bytes_per_second / 1_000_000
),
cpu = %format!("{cpu_average:.0}/{cpu_total:.0}"),
cpu = %format!("{}/{}/{}", cpu.avg_pct, cpu.median_pct, cpu.total_pct),
cpu_us_per_io_1_5_15m =
%format_1_5_15(&status.rolling, |rolling, window| {
rolling.cpu_us_per_io_over(window)
Expand Down
Loading
Loading