docker-stats-on-exit-shim

command module
v0.0.0-...-650e6e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

README

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.

Example

$ docker run --rm -ti -v`pwd`:/tmp/:rw ubuntu /tmp/docker-stats-on-exit-shim /tmp/output.json /bin/sleep 1
$ cat output.json
{
  "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
git clone git@github.com:delcypher/docker-stats-on-exit-shim.git
cd docker-stats-on-exit-shim
git submodule init && git submodule update
go get .
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.

Documentation

Overview

Copyright 2016 Dan Liew

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL