github.com/projectatomic/docker@v1.8.2/daemon/stats_linux.go (about) 1 package daemon 2 3 import ( 4 "github.com/docker/docker/api/types" 5 "github.com/opencontainers/runc/libcontainer" 6 "github.com/opencontainers/runc/libcontainer/cgroups" 7 ) 8 9 // convertStatsToAPITypes converts the libcontainer.Stats to the api specific 10 // structs. This is done to preserve API compatibility and versioning. 11 func convertStatsToAPITypes(ls *libcontainer.Stats) *types.Stats { 12 s := &types.Stats{} 13 if ls.Interfaces != nil { 14 s.Network = types.Network{} 15 for _, iface := range ls.Interfaces { 16 s.Network.RxBytes += iface.RxBytes 17 s.Network.RxPackets += iface.RxPackets 18 s.Network.RxErrors += iface.RxErrors 19 s.Network.RxDropped += iface.RxDropped 20 s.Network.TxBytes += iface.TxBytes 21 s.Network.TxPackets += iface.TxPackets 22 s.Network.TxErrors += iface.TxErrors 23 s.Network.TxDropped += iface.TxDropped 24 } 25 } 26 27 cs := ls.CgroupStats 28 if cs != nil { 29 s.BlkioStats = types.BlkioStats{ 30 IoServiceBytesRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceBytesRecursive), 31 IoServicedRecursive: copyBlkioEntry(cs.BlkioStats.IoServicedRecursive), 32 IoQueuedRecursive: copyBlkioEntry(cs.BlkioStats.IoQueuedRecursive), 33 IoServiceTimeRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceTimeRecursive), 34 IoWaitTimeRecursive: copyBlkioEntry(cs.BlkioStats.IoWaitTimeRecursive), 35 IoMergedRecursive: copyBlkioEntry(cs.BlkioStats.IoMergedRecursive), 36 IoTimeRecursive: copyBlkioEntry(cs.BlkioStats.IoTimeRecursive), 37 SectorsRecursive: copyBlkioEntry(cs.BlkioStats.SectorsRecursive), 38 } 39 cpu := cs.CpuStats 40 s.CpuStats = types.CpuStats{ 41 CpuUsage: types.CpuUsage{ 42 TotalUsage: cpu.CpuUsage.TotalUsage, 43 PercpuUsage: cpu.CpuUsage.PercpuUsage, 44 UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode, 45 UsageInUsermode: cpu.CpuUsage.UsageInUsermode, 46 }, 47 ThrottlingData: types.ThrottlingData{ 48 Periods: cpu.ThrottlingData.Periods, 49 ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods, 50 ThrottledTime: cpu.ThrottlingData.ThrottledTime, 51 }, 52 } 53 mem := cs.MemoryStats 54 s.MemoryStats = types.MemoryStats{ 55 Usage: mem.Usage.Usage, 56 MaxUsage: mem.Usage.MaxUsage, 57 Stats: mem.Stats, 58 Failcnt: mem.Usage.Failcnt, 59 } 60 } 61 62 return s 63 } 64 65 func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []types.BlkioStatEntry { 66 out := make([]types.BlkioStatEntry, len(entries)) 67 for i, re := range entries { 68 out[i] = types.BlkioStatEntry{ 69 Major: re.Major, 70 Minor: re.Minor, 71 Op: re.Op, 72 Value: re.Value, 73 } 74 } 75 return out 76 }