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"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/api"
|
"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/autogen/dockerversion"
|
||||||
"github.com/docker/docker/engine"
|
"github.com/docker/docker/engine"
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph"
|
||||||
|
@ -2640,7 +2640,7 @@ func (s *containerStats) Collect(cli *DockerCli) {
|
||||||
)
|
)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
var v *stats.Stats
|
var v *types.Stats
|
||||||
if err := dec.Decode(&v); err != nil {
|
if err := dec.Decode(&v); err != nil {
|
||||||
u <- err
|
u <- err
|
||||||
return
|
return
|
||||||
|
@ -2757,7 +2757,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateCpuPercent(previousCpu, previousSystem uint64, v *stats.Stats) float64 {
|
func calculateCpuPercent(previousCpu, previousSystem uint64, v *types.Stats) float64 {
|
||||||
var (
|
var (
|
||||||
cpuPercent = 0.0
|
cpuPercent = 0.0
|
||||||
// calculate the change for the cpu usage of the container in between readings
|
// 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
|
// This package is used for API stability in the types and response to the
|
||||||
// consumers of the API stats endpoint.
|
// consumers of the API stats endpoint.
|
||||||
package stats
|
package types
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
|
@ -3,7 +3,7 @@ package daemon
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/docker/docker/api/stats"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
"github.com/docker/docker/daemon/execdriver"
|
||||||
"github.com/docker/docker/engine"
|
"github.com/docker/docker/engine"
|
||||||
"github.com/docker/libcontainer"
|
"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
|
// convertToAPITypes converts the libcontainer.ContainerStats to the api specific
|
||||||
// structs. This is done to preserve API compatibility and versioning.
|
// structs. This is done to preserve API compatibility and versioning.
|
||||||
func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
func convertToAPITypes(ls *libcontainer.ContainerStats) *types.Stats {
|
||||||
s := &stats.Stats{}
|
s := &types.Stats{}
|
||||||
if ls.NetworkStats != nil {
|
if ls.NetworkStats != nil {
|
||||||
s.Network = stats.Network{
|
s.Network = types.Network{
|
||||||
RxBytes: ls.NetworkStats.RxBytes,
|
RxBytes: ls.NetworkStats.RxBytes,
|
||||||
RxPackets: ls.NetworkStats.RxPackets,
|
RxPackets: ls.NetworkStats.RxPackets,
|
||||||
RxErrors: ls.NetworkStats.RxErrors,
|
RxErrors: ls.NetworkStats.RxErrors,
|
||||||
|
@ -49,7 +49,7 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
||||||
}
|
}
|
||||||
cs := ls.CgroupStats
|
cs := ls.CgroupStats
|
||||||
if cs != nil {
|
if cs != nil {
|
||||||
s.BlkioStats = stats.BlkioStats{
|
s.BlkioStats = types.BlkioStats{
|
||||||
IoServiceBytesRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceBytesRecursive),
|
IoServiceBytesRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceBytesRecursive),
|
||||||
IoServicedRecursive: copyBlkioEntry(cs.BlkioStats.IoServicedRecursive),
|
IoServicedRecursive: copyBlkioEntry(cs.BlkioStats.IoServicedRecursive),
|
||||||
IoQueuedRecursive: copyBlkioEntry(cs.BlkioStats.IoQueuedRecursive),
|
IoQueuedRecursive: copyBlkioEntry(cs.BlkioStats.IoQueuedRecursive),
|
||||||
|
@ -60,21 +60,21 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
||||||
SectorsRecursive: copyBlkioEntry(cs.BlkioStats.SectorsRecursive),
|
SectorsRecursive: copyBlkioEntry(cs.BlkioStats.SectorsRecursive),
|
||||||
}
|
}
|
||||||
cpu := cs.CpuStats
|
cpu := cs.CpuStats
|
||||||
s.CpuStats = stats.CpuStats{
|
s.CpuStats = types.CpuStats{
|
||||||
CpuUsage: stats.CpuUsage{
|
CpuUsage: types.CpuUsage{
|
||||||
TotalUsage: cpu.CpuUsage.TotalUsage,
|
TotalUsage: cpu.CpuUsage.TotalUsage,
|
||||||
PercpuUsage: cpu.CpuUsage.PercpuUsage,
|
PercpuUsage: cpu.CpuUsage.PercpuUsage,
|
||||||
UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode,
|
UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode,
|
||||||
UsageInUsermode: cpu.CpuUsage.UsageInUsermode,
|
UsageInUsermode: cpu.CpuUsage.UsageInUsermode,
|
||||||
},
|
},
|
||||||
ThrottlingData: stats.ThrottlingData{
|
ThrottlingData: types.ThrottlingData{
|
||||||
Periods: cpu.ThrottlingData.Periods,
|
Periods: cpu.ThrottlingData.Periods,
|
||||||
ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods,
|
ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods,
|
||||||
ThrottledTime: cpu.ThrottlingData.ThrottledTime,
|
ThrottledTime: cpu.ThrottlingData.ThrottledTime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
mem := cs.MemoryStats
|
mem := cs.MemoryStats
|
||||||
s.MemoryStats = stats.MemoryStats{
|
s.MemoryStats = types.MemoryStats{
|
||||||
Usage: mem.Usage,
|
Usage: mem.Usage,
|
||||||
MaxUsage: mem.MaxUsage,
|
MaxUsage: mem.MaxUsage,
|
||||||
Stats: mem.Stats,
|
Stats: mem.Stats,
|
||||||
|
@ -84,10 +84,10 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []stats.BlkioStatEntry {
|
func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []types.BlkioStatEntry {
|
||||||
out := make([]stats.BlkioStatEntry, len(entries))
|
out := make([]types.BlkioStatEntry, len(entries))
|
||||||
for i, re := range entries {
|
for i, re := range entries {
|
||||||
out[i] = stats.BlkioStatEntry{
|
out[i] = types.BlkioStatEntry{
|
||||||
Major: re.Major,
|
Major: re.Major,
|
||||||
Minor: re.Minor,
|
Minor: re.Minor,
|
||||||
Op: re.Op,
|
Op: re.Op,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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"
|
"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))
|
dec := json.NewDecoder(bytes.NewBuffer(sr.body))
|
||||||
var s *stats.Stats
|
var s *types.Stats
|
||||||
// decode only one object from the stream
|
// decode only one object from the stream
|
||||||
if err := dec.Decode(&s); err != nil {
|
if err := dec.Decode(&s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Reference in a new issue