Browse code

Windows: refactor stats

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2015/05/16 07:02:11
Showing 4 changed files
... ...
@@ -48,6 +48,7 @@ type MemoryStats struct {
48 48
 	Limit   uint64 `json:"limit"`
49 49
 }
50 50
 
51
+// TODO Windows: This can be factored out
51 52
 type BlkioStatEntry struct {
52 53
 	Major uint64 `json:"major"`
53 54
 	Minor uint64 `json:"minor"`
... ...
@@ -55,6 +56,7 @@ type BlkioStatEntry struct {
55 55
 	Value uint64 `json:"value"`
56 56
 }
57 57
 
58
+// TODO Windows: This can be factored out
58 59
 type BlkioStats struct {
59 60
 	// number of bytes tranferred to and from the block device
60 61
 	IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive"`
... ...
@@ -67,6 +69,7 @@ type BlkioStats struct {
67 67
 	SectorsRecursive        []BlkioStatEntry `json:"sectors_recursive"`
68 68
 }
69 69
 
70
+// TODO Windows: This will require refactoring
70 71
 type Network struct {
71 72
 	RxBytes   uint64 `json:"rx_bytes"`
72 73
 	RxPackets uint64 `json:"rx_packets"`
... ...
@@ -4,10 +4,7 @@ import (
4 4
 	"encoding/json"
5 5
 	"io"
6 6
 
7
-	"github.com/docker/docker/api/types"
8 7
 	"github.com/docker/docker/daemon/execdriver"
9
-	"github.com/docker/libcontainer"
10
-	"github.com/docker/libcontainer/cgroups"
11 8
 )
12 9
 
13 10
 func (daemon *Daemon) ContainerStats(name string, stream bool, out io.Writer) error {
... ...
@@ -33,70 +30,3 @@ func (daemon *Daemon) ContainerStats(name string, stream bool, out io.Writer) er
33 33
 	}
34 34
 	return nil
35 35
 }
36
-
37
-// convertToAPITypes converts the libcontainer.Stats to the api specific
38
-// structs.  This is done to preserve API compatibility and versioning.
39
-func convertToAPITypes(ls *libcontainer.Stats) *types.Stats {
40
-	s := &types.Stats{}
41
-	if ls.Interfaces != nil {
42
-		s.Network = types.Network{}
43
-		for _, iface := range ls.Interfaces {
44
-			s.Network.RxBytes += iface.RxBytes
45
-			s.Network.RxPackets += iface.RxPackets
46
-			s.Network.RxErrors += iface.RxErrors
47
-			s.Network.RxDropped += iface.RxDropped
48
-			s.Network.TxBytes += iface.TxBytes
49
-			s.Network.TxPackets += iface.TxPackets
50
-			s.Network.TxErrors += iface.TxErrors
51
-			s.Network.TxDropped += iface.TxDropped
52
-		}
53
-	}
54
-	cs := ls.CgroupStats
55
-	if cs != nil {
56
-		s.BlkioStats = types.BlkioStats{
57
-			IoServiceBytesRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceBytesRecursive),
58
-			IoServicedRecursive:     copyBlkioEntry(cs.BlkioStats.IoServicedRecursive),
59
-			IoQueuedRecursive:       copyBlkioEntry(cs.BlkioStats.IoQueuedRecursive),
60
-			IoServiceTimeRecursive:  copyBlkioEntry(cs.BlkioStats.IoServiceTimeRecursive),
61
-			IoWaitTimeRecursive:     copyBlkioEntry(cs.BlkioStats.IoWaitTimeRecursive),
62
-			IoMergedRecursive:       copyBlkioEntry(cs.BlkioStats.IoMergedRecursive),
63
-			IoTimeRecursive:         copyBlkioEntry(cs.BlkioStats.IoTimeRecursive),
64
-			SectorsRecursive:        copyBlkioEntry(cs.BlkioStats.SectorsRecursive),
65
-		}
66
-		cpu := cs.CpuStats
67
-		s.CpuStats = types.CpuStats{
68
-			CpuUsage: types.CpuUsage{
69
-				TotalUsage:        cpu.CpuUsage.TotalUsage,
70
-				PercpuUsage:       cpu.CpuUsage.PercpuUsage,
71
-				UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode,
72
-				UsageInUsermode:   cpu.CpuUsage.UsageInUsermode,
73
-			},
74
-			ThrottlingData: types.ThrottlingData{
75
-				Periods:          cpu.ThrottlingData.Periods,
76
-				ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods,
77
-				ThrottledTime:    cpu.ThrottlingData.ThrottledTime,
78
-			},
79
-		}
80
-		mem := cs.MemoryStats
81
-		s.MemoryStats = types.MemoryStats{
82
-			Usage:    mem.Usage,
83
-			MaxUsage: mem.MaxUsage,
84
-			Stats:    mem.Stats,
85
-			Failcnt:  mem.Failcnt,
86
-		}
87
-	}
88
-	return s
89
-}
90
-
91
-func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []types.BlkioStatEntry {
92
-	out := make([]types.BlkioStatEntry, len(entries))
93
-	for i, re := range entries {
94
-		out[i] = types.BlkioStatEntry{
95
-			Major: re.Major,
96
-			Minor: re.Minor,
97
-			Op:    re.Op,
98
-			Value: re.Value,
99
-		}
100
-	}
101
-	return out
102
-}
103 36
new file mode 100644
... ...
@@ -0,0 +1,76 @@
0
+package daemon
1
+
2
+import (
3
+	"github.com/docker/docker/api/types"
4
+	"github.com/docker/libcontainer"
5
+	"github.com/docker/libcontainer/cgroups"
6
+)
7
+
8
+// convertToAPITypes converts the libcontainer.Stats to the api specific
9
+// structs.  This is done to preserve API compatibility and versioning.
10
+func convertToAPITypes(ls *libcontainer.Stats) *types.Stats {
11
+	s := &types.Stats{}
12
+	if ls.Interfaces != nil {
13
+		s.Network = types.Network{}
14
+		for _, iface := range ls.Interfaces {
15
+			s.Network.RxBytes += iface.RxBytes
16
+			s.Network.RxPackets += iface.RxPackets
17
+			s.Network.RxErrors += iface.RxErrors
18
+			s.Network.RxDropped += iface.RxDropped
19
+			s.Network.TxBytes += iface.TxBytes
20
+			s.Network.TxPackets += iface.TxPackets
21
+			s.Network.TxErrors += iface.TxErrors
22
+			s.Network.TxDropped += iface.TxDropped
23
+		}
24
+	}
25
+
26
+	cs := ls.CgroupStats
27
+	if cs != nil {
28
+		s.BlkioStats = types.BlkioStats{
29
+			IoServiceBytesRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceBytesRecursive),
30
+			IoServicedRecursive:     copyBlkioEntry(cs.BlkioStats.IoServicedRecursive),
31
+			IoQueuedRecursive:       copyBlkioEntry(cs.BlkioStats.IoQueuedRecursive),
32
+			IoServiceTimeRecursive:  copyBlkioEntry(cs.BlkioStats.IoServiceTimeRecursive),
33
+			IoWaitTimeRecursive:     copyBlkioEntry(cs.BlkioStats.IoWaitTimeRecursive),
34
+			IoMergedRecursive:       copyBlkioEntry(cs.BlkioStats.IoMergedRecursive),
35
+			IoTimeRecursive:         copyBlkioEntry(cs.BlkioStats.IoTimeRecursive),
36
+			SectorsRecursive:        copyBlkioEntry(cs.BlkioStats.SectorsRecursive),
37
+		}
38
+		cpu := cs.CpuStats
39
+		s.CpuStats = types.CpuStats{
40
+			CpuUsage: types.CpuUsage{
41
+				TotalUsage:        cpu.CpuUsage.TotalUsage,
42
+				PercpuUsage:       cpu.CpuUsage.PercpuUsage,
43
+				UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode,
44
+				UsageInUsermode:   cpu.CpuUsage.UsageInUsermode,
45
+			},
46
+			ThrottlingData: types.ThrottlingData{
47
+				Periods:          cpu.ThrottlingData.Periods,
48
+				ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods,
49
+				ThrottledTime:    cpu.ThrottlingData.ThrottledTime,
50
+			},
51
+		}
52
+		mem := cs.MemoryStats
53
+		s.MemoryStats = types.MemoryStats{
54
+			Usage:    mem.Usage,
55
+			MaxUsage: mem.MaxUsage,
56
+			Stats:    mem.Stats,
57
+			Failcnt:  mem.Failcnt,
58
+		}
59
+	}
60
+
61
+	return s
62
+}
63
+
64
+func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []types.BlkioStatEntry {
65
+	out := make([]types.BlkioStatEntry, len(entries))
66
+	for i, re := range entries {
67
+		out[i] = types.BlkioStatEntry{
68
+			Major: re.Major,
69
+			Minor: re.Minor,
70
+			Op:    re.Op,
71
+			Value: re.Value,
72
+		}
73
+	}
74
+	return out
75
+}
0 76
new file mode 100644
... ...
@@ -0,0 +1,14 @@
0
+package daemon
1
+
2
+import (
3
+	"github.com/docker/docker/api/types"
4
+	"github.com/docker/libcontainer"
5
+)
6
+
7
+// convertToAPITypes converts the libcontainer.Stats to the api specific
8
+// structs.  This is done to preserve API compatibility and versioning.
9
+func convertToAPITypes(ls *libcontainer.Stats) *types.Stats {
10
+	// TODO Windows. Refactor accordingly to fill in stats.
11
+	s := &types.Stats{}
12
+	return s
13
+}