Merge branch 'stats'
This commit is contained in:
		| @@ -13,6 +13,7 @@ import ( | |||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"syscall" | 	"syscall" | ||||||
|  | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/docker/containerd/runtime" | 	"github.com/docker/containerd/runtime" | ||||||
| 	"github.com/opencontainers/runc/libcontainer" | 	"github.com/opencontainers/runc/libcontainer" | ||||||
| @@ -304,6 +305,18 @@ func (c *libcontainerContainer) SetExited(status int) { | |||||||
| 	c.exited = true | 	c.exited = true | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (c *libcontainerContainer) Stats() (*runtime.Stat, error) { | ||||||
|  | 	now := time.Now() | ||||||
|  | 	stats, err := c.c.Stats() | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 	return &runtime.Stat{ | ||||||
|  | 		Timestamp: now, | ||||||
|  | 		Data:      stats, | ||||||
|  | 	}, nil | ||||||
|  | } | ||||||
|  |  | ||||||
| func (c *libcontainerContainer) Delete() error { | func (c *libcontainerContainer) Delete() error { | ||||||
| 	return c.c.Destroy() | 	return c.c.Destroy() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -37,6 +37,10 @@ func (c *runcContainer) Start() error { | |||||||
| 	return c.initProcess.cmd.Start() | 	return c.initProcess.cmd.Start() | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (c *runcContainer) Stats() (*runtime.Stat, error) { | ||||||
|  | 	return nil, errors.New("containerd: runc does not support stats in containerd") | ||||||
|  | } | ||||||
|  |  | ||||||
| func (c *runcContainer) Path() string { | func (c *runcContainer) Path() string { | ||||||
| 	return c.path | 	return c.path | ||||||
| } | } | ||||||
|   | |||||||
| @@ -29,6 +29,16 @@ type Stdio struct { | |||||||
| 	Stdout string | 	Stdout string | ||||||
| } | } | ||||||
|  |  | ||||||
|  | type Stat struct { | ||||||
|  | 	// Timestamp is the time that the statistics where collected | ||||||
|  | 	Timestamp time.Time | ||||||
|  | 	// Data is the raw stats | ||||||
|  | 	// TODO: it is currently an interface because we don't know what type of exec drivers | ||||||
|  | 	// we will have or what the structure should look like at the moment os the containers | ||||||
|  | 	// can return what they want and we could marshal to json or whatever. | ||||||
|  | 	Data interface{} | ||||||
|  | } | ||||||
|  |  | ||||||
| type Checkpoint struct { | type Checkpoint struct { | ||||||
| 	// Timestamp is the time that checkpoint happened | 	// Timestamp is the time that checkpoint happened | ||||||
| 	Timestamp time.Time | 	Timestamp time.Time | ||||||
| @@ -75,4 +85,6 @@ type Container interface { | |||||||
| 	DeleteCheckpoint(name string) error | 	DeleteCheckpoint(name string) error | ||||||
| 	// Restore restores the container to that of the checkpoint provided by name | 	// Restore restores the container to that of the checkpoint provided by name | ||||||
| 	Restore(name string) error | 	Restore(name string) error | ||||||
|  | 	// Stats returns realtime container stats and resource information | ||||||
|  | 	Stats() (*Stat, error) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,10 +11,13 @@ var ( | |||||||
| 	ErrInvalidContainerType = errors.New("containerd: invalid container type for runtime") | 	ErrInvalidContainerType = errors.New("containerd: invalid container type for runtime") | ||||||
| 	ErrCheckpointNotExists  = errors.New("containerd: checkpoint does not exist for container") | 	ErrCheckpointNotExists  = errors.New("containerd: checkpoint does not exist for container") | ||||||
| 	ErrCheckpointExists     = errors.New("containerd: checkpoint already exists") | 	ErrCheckpointExists     = errors.New("containerd: checkpoint already exists") | ||||||
|  | 	ErrContainerExited      = errors.New("containerd: container has exited") | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // runtime handles containers, containers handle their own actions. | // Runtime handles containers, containers handle their own actions | ||||||
| type Runtime interface { | type Runtime interface { | ||||||
|  | 	// Create creates a new container initialized but without it starting it | ||||||
| 	Create(id, bundlePath string, stdio *Stdio) (Container, error) | 	Create(id, bundlePath string, stdio *Stdio) (Container, error) | ||||||
|  | 	// StartProcess adds a new process to the container | ||||||
| 	StartProcess(Container, specs.Process, *Stdio) (Process, error) | 	StartProcess(Container, specs.Process, *Stdio) (Process, error) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Crosby
					Michael Crosby