Code Monkey home page Code Monkey logo

docker-stats-on-exit-shim's Introduction

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 [email protected]: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.

docker-stats-on-exit-shim's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

docker-stats-on-exit-shim's Issues

Help needed to test

Hi
I am interested in this project and trying to test it.
When I ran go get . it asked me to run go mod init so I did it.
And then I found

$ go get .
go: downloading github.com/opencontainers/runc v1.0.2
go: downloading github.com/moby/sys/mountinfo v0.4.1
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/cyphar/filepath-securejoin v0.2.2
go: downloading github.com/sirupsen/logrus v1.8.1
go: downloading golang.org/x/sys v0.0.0-20210426230700-d19ff857e887
go: downloading github.com/coreos/go-systemd/v22 v22.3.2
go: downloading github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
go: downloading github.com/godbus/dbus/v5 v5.0.4
# github.com/opencontainers/runc/libcontainer/cgroups
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:79:14: undefined: unix.Openat2
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:79:45: undefined: unix.OpenHow
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:100:18: undefined: unix.RESOLVE_BENEATH
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:100:41: undefined: unix.RESOLVE_NO_MAGICLINKS
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:101:17: undefined: unix.CGROUP2_SUPER_MAGIC
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:103:20: undefined: unix.RESOLVE_NO_XDEV
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:103:43: undefined: unix.RESOLVE_NO_SYMLINKS
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/v1_utils.go:155:9: undefined: Mount
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/v1_utils.go:163:87: undefined: Mount
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/v1_utils.go:191:37: undefined: Mount
../../../../pkg/mod/github.com/opencontainers/[email protected]/libcontainer/cgroups/file.go:103:43: too many errors

Can you help me to test it?
Thanks,
Seung

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.