Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make /proc/diskstats compatible with Kernel 4.18+ #39

Merged
merged 1 commit into from
May 20, 2019
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
2 changes: 2 additions & 0 deletions fixtures/linux/disk_stats/proc_diskstats_4_18
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
8 0 sda 6185 9367 403272 22160 2591 8251 84452 2860 0 8960 24990 0 0 0 0
8 1 sda1 483 4782 41466 1100 7 1 28 40 0 930 1140 0 0 0 0
42 changes: 41 additions & 1 deletion src/disk_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ mod os {
let line = line_result.map_err(|e| ProbeError::IO(e, path_to_string(path)))?;
let segments: Vec<&str> = line.split_whitespace().collect();

if segments.len() != 14 {
// /proc/disktats has 14 fields, or 18 fields for kernel 4.18+
if segments.len() != 14 && segments.len() != 18 {
return Err(ProbeError::UnexpectedContent("Incorrect number of segments".to_owned()))
}

Expand Down Expand Up @@ -182,6 +183,45 @@ mod tests {
assert_eq!(1140, sda1.weighted_time_spent_doing_ios_ms);
}

#[test]
fn test_read_and_parse_proc_diskstats_kernel_4_18_plus() {
let measurement = read_and_parse_proc_diskstats(&Path::new("fixtures/linux/disk_stats/proc_diskstats_4_18")).unwrap();

assert!(measurement.precise_time_ns > 0);

assert_eq!(2, measurement.stats.len());

let sda = measurement.stats.get("sda").unwrap();
assert_eq!(6185, sda.reads_completed_successfully);
assert_eq!(9367, sda.reads_merged);
assert_eq!(403272, sda.sectors_read);
assert_eq!(206475264, sda.bytes_read());
assert_eq!(22160, sda.time_spent_reading_ms);
assert_eq!(2591, sda.writes_completed);
assert_eq!(8251, sda.writes_merged);
assert_eq!(84452, sda.sectors_written);
assert_eq!(43239424, sda.bytes_written());
assert_eq!(2860, sda.time_spent_writing_ms);
assert_eq!(0, sda.ios_currently_in_progress);
assert_eq!(8960, sda.time_spent_doing_ios_ms);
assert_eq!(24990, sda.weighted_time_spent_doing_ios_ms);

let sda1 = measurement.stats.get("sda1").unwrap();
assert_eq!(483, sda1.reads_completed_successfully);
assert_eq!(4782, sda1.reads_merged);
assert_eq!(41466, sda1.sectors_read);
assert_eq!(21230592, sda1.bytes_read());
assert_eq!(1100, sda1.time_spent_reading_ms);
assert_eq!(7, sda1.writes_completed);
assert_eq!(1, sda1.writes_merged);
assert_eq!(28, sda1.sectors_written);
assert_eq!(14336, sda1.bytes_written());
assert_eq!(40, sda1.time_spent_writing_ms);
assert_eq!(0, sda1.ios_currently_in_progress);
assert_eq!(930, sda1.time_spent_doing_ios_ms);
assert_eq!(1140, sda1.weighted_time_spent_doing_ios_ms);
}

#[test]
fn test_read_and_parse_proc_diskstats_incomplete() {
match read_and_parse_proc_diskstats(&Path::new("fixtures/linux/disk_stats/proc_diskstats_incomplete")) {
Expand Down