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

Add metrics for disk reads and writes per cgroup #121

Merged
merged 1 commit into from
Nov 30, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Add metrics from `/proc/[pid]/io`
- Add metrics for disk reads and writes per cgroup

### Changed

Expand Down
14 changes: 10 additions & 4 deletions metric/system/cgroup/cgv1/blkio.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ import (
//
// https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt
type BlockIOSubsystem struct {
ID string `json:"id,omitempty"` // ID of the cgroup.
Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint.
Total TotalIOs `json:"total,omitempty" struct:"total"` // Throttle limits for upper IO rates and metrics.
//CFQ CFQScheduler `json:"cfq,omitempty"` // Completely fair queue scheduler limits and metrics.
ID string `json:"id,omitempty"` // ID of the cgroup.
Path string `json:"path,omitempty"` // Path to the cgroup relative to the cgroup subsystem's mountpoint.
Total TotalIOs `json:"total,omitempty" struct:"total"` // Throttle limits for upper IO rates and metrics.
Reads TotalIOs `json:"reads,omitempty" struct:"reads"` // Throttle limits for upper IO rates and metrics.
Writes TotalIOs `json:"writes,omitempty" struct:"writes"` // Throttle limits for upper IO rates and metrics.
//CFQ CFQScheduler `json:"cfq,omitempty"` // Completely fair queue scheduler limits and metrics.
}

// TotalIOs wraps the totals for blkio
Expand Down Expand Up @@ -196,6 +198,10 @@ func blkioThrottle(path string, blkio *BlockIOSubsystem) error {
for _, dev := range devices {
blkio.Total.Bytes += dev.Bytes.Read + dev.Bytes.Write
blkio.Total.Ios += dev.IOs.Read + dev.IOs.Write
blkio.Reads.Bytes += dev.Bytes.Read
blkio.Reads.Ios += dev.IOs.Read
blkio.Writes.Bytes += dev.Bytes.Write
blkio.Writes.Ios += dev.IOs.Write
}
return nil
}
Expand Down
8 changes: 6 additions & 2 deletions metric/system/cgroup/cgv1/blkio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ func TestBlkioThrottle(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Equal(t, uint64(46), blkio.Total.Ios)
assert.Equal(t, uint64(1648128), blkio.Total.Bytes)
assert.Equal(t, uint64(48), blkio.Total.Ios)
assert.Equal(t, uint64(1651200), blkio.Total.Bytes)
assert.Equal(t, uint64(46), blkio.Reads.Ios)
assert.Equal(t, uint64(1648128), blkio.Reads.Bytes)
assert.Equal(t, uint64(2), blkio.Writes.Ios)
assert.Equal(t, uint64(3072), blkio.Writes.Bytes)

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
7:0 Read 4608
7:0 Write 0
7:0 Write 1024
7:0 Sync 0
7:0 Async 4608
7:0 Total 4608
7:0 Async 5632
7:0 Total 5632
253:0 Read 4608
253:0 Write 0
253:0 Write 2048
253:0 Sync 0
253:0 Async 4608
253:0 Total 4608
253:0 Async 6656
253:0 Total 6656
253:1 Read 1638912
253:1 Write 0
253:1 Sync 0
253:1 Async 1638912
253:1 Total 1638912
Total 1648128
Total 1651200
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
7:0 Read 2
7:0 Write 0
7:0 Write 1
7:0 Sync 0
7:0 Async 2
7:0 Total 2
7:0 Async 3
7:0 Total 3
253:0 Read 2
253:0 Write 0
253:0 Write 1
253:0 Sync 0
253:0 Async 2
253:0 Total 2
253:1 Read 42
253:1 Write 0
253:1 Sync 0
253:1 Async 42
253:1 Total 42
Total 46
253:1 Async 43
253:1 Total 43
Total 48