https://github.com/justintimperio/dockerstats
Collect Docker Performance Stats in Go
https://github.com/justintimperio/dockerstats
Last synced: 8 months ago
JSON representation
Collect Docker Performance Stats in Go
- Host: GitHub
- URL: https://github.com/justintimperio/dockerstats
- Owner: JustinTimperio
- License: mit
- Created: 2022-08-17T22:20:22.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-17T22:27:02.000Z (almost 4 years ago)
- Last Synced: 2025-10-13T08:43:44.220Z (9 months ago)
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker-Stats-Go
Package docker-stats-go provides the ability to get currently running Docker
container statistics, including memory and CPU usage.
To get the statistics of running Docker containers, you can use the `Current()`
function:
stats, err := dsg.Current()
if err != nil {
panic(err)
}
for _, s := range stats {
fmt.Println(s.Container) // 9f2656020722
fmt.Println(s.Memory) // {Raw=221.7 MiB / 7.787 GiB, Percent=2.78%}
fmt.Println(s.CPU) // 99.79%
}
Alternatively, you can use the `NewMonitor()` function to receive a constant
stream of Docker container stats, available on the Monitor's `Stream` channel:
m := dsg.NewMonitor()
for res := range m.Stream {
if res.Error != nil {
panic(err)
}
for _, s := range res.Stats {
fmt.Println(s.Container) // 9f2656020722
}
}