mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move stats api types into api/types package
Move the stats structs from the api/stats package into a new package api/types that will contain all the api structs for docker's api request and responses. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
1d27930faa
commit
7fed7d7eb4
4 changed files with 18 additions and 18 deletions
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/stats"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/autogen/dockerversion"
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/graph"
|
||||
|
@ -2640,7 +2640,7 @@ func (s *containerStats) Collect(cli *DockerCli) {
|
|||
)
|
||||
go func() {
|
||||
for {
|
||||
var v *stats.Stats
|
||||
var v *types.Stats
|
||||
if err := dec.Decode(&v); err != nil {
|
||||
u <- err
|
||||
return
|
||||
|
@ -2757,7 +2757,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func calculateCpuPercent(previousCpu, previousSystem uint64, v *stats.Stats) float64 {
|
||||
func calculateCpuPercent(previousCpu, previousSystem uint64, v *types.Stats) float64 {
|
||||
var (
|
||||
cpuPercent = 0.0
|
||||
// calculate the change for the cpu usage of the container in between readings
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// This package is used for API stability in the types and response to the
|
||||
// consumers of the API stats endpoint.
|
||||
package stats
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
|
@ -3,7 +3,7 @@ package daemon
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/docker/docker/api/stats"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/daemon/execdriver"
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/libcontainer"
|
||||
|
@ -33,10 +33,10 @@ func (daemon *Daemon) ContainerStats(job *engine.Job) engine.Status {
|
|||
|
||||
// convertToAPITypes converts the libcontainer.ContainerStats to the api specific
|
||||
// structs. This is done to preserve API compatibility and versioning.
|
||||
func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
||||
s := &stats.Stats{}
|
||||
func convertToAPITypes(ls *libcontainer.ContainerStats) *types.Stats {
|
||||
s := &types.Stats{}
|
||||
if ls.NetworkStats != nil {
|
||||
s.Network = stats.Network{
|
||||
s.Network = types.Network{
|
||||
RxBytes: ls.NetworkStats.RxBytes,
|
||||
RxPackets: ls.NetworkStats.RxPackets,
|
||||
RxErrors: ls.NetworkStats.RxErrors,
|
||||
|
@ -49,7 +49,7 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
|||
}
|
||||
cs := ls.CgroupStats
|
||||
if cs != nil {
|
||||
s.BlkioStats = stats.BlkioStats{
|
||||
s.BlkioStats = types.BlkioStats{
|
||||
IoServiceBytesRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceBytesRecursive),
|
||||
IoServicedRecursive: copyBlkioEntry(cs.BlkioStats.IoServicedRecursive),
|
||||
IoQueuedRecursive: copyBlkioEntry(cs.BlkioStats.IoQueuedRecursive),
|
||||
|
@ -60,21 +60,21 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
|||
SectorsRecursive: copyBlkioEntry(cs.BlkioStats.SectorsRecursive),
|
||||
}
|
||||
cpu := cs.CpuStats
|
||||
s.CpuStats = stats.CpuStats{
|
||||
CpuUsage: stats.CpuUsage{
|
||||
s.CpuStats = types.CpuStats{
|
||||
CpuUsage: types.CpuUsage{
|
||||
TotalUsage: cpu.CpuUsage.TotalUsage,
|
||||
PercpuUsage: cpu.CpuUsage.PercpuUsage,
|
||||
UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode,
|
||||
UsageInUsermode: cpu.CpuUsage.UsageInUsermode,
|
||||
},
|
||||
ThrottlingData: stats.ThrottlingData{
|
||||
ThrottlingData: types.ThrottlingData{
|
||||
Periods: cpu.ThrottlingData.Periods,
|
||||
ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods,
|
||||
ThrottledTime: cpu.ThrottlingData.ThrottledTime,
|
||||
},
|
||||
}
|
||||
mem := cs.MemoryStats
|
||||
s.MemoryStats = stats.MemoryStats{
|
||||
s.MemoryStats = types.MemoryStats{
|
||||
Usage: mem.Usage,
|
||||
MaxUsage: mem.MaxUsage,
|
||||
Stats: mem.Stats,
|
||||
|
@ -84,10 +84,10 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
|||
return s
|
||||
}
|
||||
|
||||
func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []stats.BlkioStatEntry {
|
||||
out := make([]stats.BlkioStatEntry, len(entries))
|
||||
func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []types.BlkioStatEntry {
|
||||
out := make([]types.BlkioStatEntry, len(entries))
|
||||
for i, re := range entries {
|
||||
out[i] = stats.BlkioStatEntry{
|
||||
out[i] = types.BlkioStatEntry{
|
||||
Major: re.Major,
|
||||
Minor: re.Minor,
|
||||
Op: re.Op,
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/stats"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
||||
)
|
||||
|
||||
|
@ -311,7 +311,7 @@ func TestGetContainerStats(t *testing.T) {
|
|||
}
|
||||
|
||||
dec := json.NewDecoder(bytes.NewBuffer(sr.body))
|
||||
var s *stats.Stats
|
||||
var s *types.Stats
|
||||
// decode only one object from the stream
|
||||
if err := dec.Decode(&s); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
Loading…
Reference in a new issue