Skip to content

hasnat/docker-stats-on-exit-shim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Stats On Exit Shim

Build Status

This is a small utility designed to capture the statistics for the run of a Docker container before its destruction.

It is designed to be used as the main process of a Docker container that wraps the real command by waiting for it to exit and then querying the active Cgroup subsystems to gather their statistics. It dumps these statistics to a file as JSON and then exits with the exit code of the real command.

Environment variables

  • STATS_OUTPUT_FILE=/dev/stdout file path you want your output to be saved to (Default /dev/stdout)
  • STATS_OUTPUT_PREFIX= any prefix you want to add before stats output (Default blank)
  • STATS_OUTPUT_MINIFIED=false true|false (Default true)

Example

Dockerfile

COPY --from=hasnat/docker-stats-on-exit-shim /docker-stats-on-exit-shim .
ENTRYPOINT ["/docker-stats-on-exit-shim"]
CMD ["sleep", "1"]

Example Run

$ docker run --rm -ti hasnat/docker-stats-on-exit-shim /bin/sleep 1

Output example

{
  "wall_time": 1000765975,
  "user_cpu_time": 0,
  "sys_cpu_time": 0,
  "cgroups": {
    "cpu_stats": {
      "cpu_usage": {
        "total_usage": 21326399,
        "percpu_usage": [
          14721062,
          1512284,
          1730836,
          3362217,
          0,
          0,
          0,
          0
        ],
        "usage_in_kernelmode": 0,
        "usage_in_usermode": 10000000
      },
      "throttling_data": {}
    },
    "memory_stats": {
    ...
    }
  }
}

Building

mkdir -p src/github.com/delcypher
export GOPATH=`pwd`
cd src/github.com/delcypher
dep ensure
go build

Caveats

  • The recorded statistics won't quite be before container destruction but it's probably close enough.
  • The recorded statistics will contain the run of the tool (i.e. it will contribute to CPU usage). It should be a very small contribution though.

About

Simple tool to record Docker container statistics before its destruction

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 93.0%
  • Dockerfile 7.0%