-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 docker diskio stats on Windows #8126
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
67fbc42
Add docker diskio stats on Windows
jsoriano 5324aba
Use same code for windows and unix docker diskio
jsoriano de1e6ed
Add test for docker blkio windows storage stats
jsoriano 4bc9ce5
Added comment
jsoriano fe96864
Added more comments
jsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,28 @@ type BlkioStats struct { | |
servicedBytes BlkioRaw | ||
} | ||
|
||
func (s *BlkioStats) Add(o *BlkioStats) { | ||
s.reads += o.reads | ||
s.writes += o.writes | ||
s.totals += o.totals | ||
|
||
s.serviced.Add(&o.serviced) | ||
s.servicedBytes.Add(&o.servicedBytes) | ||
} | ||
|
||
type BlkioRaw struct { | ||
Time time.Time | ||
reads uint64 | ||
writes uint64 | ||
totals uint64 | ||
} | ||
|
||
func (s *BlkioRaw) Add(o *BlkioRaw) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method BlkioRaw.Add should have comment or be unexported |
||
s.reads += o.reads | ||
s.writes += o.writes | ||
s.totals += o.totals | ||
} | ||
|
||
// BlkioService is a helper to collect and calculate disk I/O metrics | ||
type BlkioService struct { | ||
lastStatsPerContainer map[string]BlkioRaw | ||
|
@@ -61,34 +76,55 @@ func (io *BlkioService) getBlkioStatsList(rawStats []docker.Stat, dedot bool) [] | |
statsPerContainer := make(map[string]BlkioRaw) | ||
for _, myRawStats := range rawStats { | ||
stats := io.getBlkioStats(&myRawStats, dedot) | ||
statsPerContainer[myRawStats.Container.ID] = stats.serviced | ||
storageStats := io.getStorageStats(&myRawStats, dedot) | ||
stats.Add(&storageStats) | ||
|
||
oldStats, exist := io.lastStatsPerContainer[stats.Container.ID] | ||
if exist { | ||
stats.reads = io.getReadPs(&oldStats, &stats.serviced) | ||
stats.writes = io.getWritePs(&oldStats, &stats.serviced) | ||
stats.totals = io.getTotalPs(&oldStats, &stats.serviced) | ||
} | ||
|
||
statsPerContainer[stats.Container.ID] = stats.serviced | ||
formattedStats = append(formattedStats, stats) | ||
} | ||
|
||
io.lastStatsPerContainer = statsPerContainer | ||
return formattedStats | ||
} | ||
|
||
func (io *BlkioService) getBlkioStats(myRawStat *docker.Stat, dedot bool) BlkioStats { | ||
newBlkioStats := io.getNewStats(myRawStat.Stats.Read, myRawStat.Stats.BlkioStats.IoServicedRecursive) | ||
bytesBlkioStats := io.getNewStats(myRawStat.Stats.Read, myRawStat.Stats.BlkioStats.IoServiceBytesRecursive) | ||
func (io *BlkioService) getStorageStats(myRawStats *docker.Stat, dedot bool) BlkioStats { | ||
return BlkioStats{ | ||
Time: myRawStats.Stats.Read, | ||
Container: docker.NewContainer(myRawStats.Container, dedot), | ||
|
||
serviced: BlkioRaw{ | ||
reads: myRawStats.Stats.StorageStats.ReadCountNormalized, | ||
writes: myRawStats.Stats.StorageStats.WriteCountNormalized, | ||
totals: myRawStats.Stats.StorageStats.ReadCountNormalized + myRawStats.Stats.StorageStats.WriteCountNormalized, | ||
}, | ||
|
||
servicedBytes: BlkioRaw{ | ||
reads: myRawStats.Stats.StorageStats.ReadSizeBytes, | ||
writes: myRawStats.Stats.StorageStats.WriteSizeBytes, | ||
totals: myRawStats.Stats.StorageStats.ReadSizeBytes + myRawStats.Stats.StorageStats.WriteSizeBytes, | ||
}, | ||
} | ||
} | ||
|
||
myBlkioStats := BlkioStats{ | ||
func (io *BlkioService) getBlkioStats(myRawStat *docker.Stat, dedot bool) BlkioStats { | ||
return BlkioStats{ | ||
Time: myRawStat.Stats.Read, | ||
Container: docker.NewContainer(myRawStat.Container, dedot), | ||
|
||
serviced: newBlkioStats, | ||
servicedBytes: bytesBlkioStats, | ||
serviced: io.getNewStats( | ||
myRawStat.Stats.Read, | ||
myRawStat.Stats.BlkioStats.IoServicedRecursive), | ||
servicedBytes: io.getNewStats( | ||
myRawStat.Stats.Read, | ||
myRawStat.Stats.BlkioStats.IoServiceBytesRecursive), | ||
} | ||
|
||
oldBlkioStats, exist := io.lastStatsPerContainer[myRawStat.Container.ID] | ||
if exist { | ||
myBlkioStats.reads = io.getReadPs(&oldBlkioStats, &newBlkioStats) | ||
myBlkioStats.writes = io.getWritePs(&oldBlkioStats, &newBlkioStats) | ||
myBlkioStats.totals = io.getTotalPs(&oldBlkioStats, &newBlkioStats) | ||
} | ||
|
||
return myBlkioStats | ||
} | ||
|
||
func (io *BlkioService) getNewStats(time time.Time, blkioEntry []types.BlkioStatEntry) BlkioRaw { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method BlkioStats.Add should have comment or be unexported