Skip to content

Commit

Permalink
networks stats test for docker api 1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen Sy Thanh Son committed Dec 15, 2015
1 parent 7177a9e commit adc42c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
25 changes: 14 additions & 11 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,17 +635,8 @@ func (c *Client) TopContainer(id string, psArgs string) (TopResult, error) {
//
// See https://goo.gl/GNmLHb for more details.
type Stats struct {
Read time.Time `json:"read,omitempty" yaml:"read,omitempty"`
Network struct {
RxDropped uint64 `json:"rx_dropped,omitempty" yaml:"rx_dropped,omitempty"`
RxBytes uint64 `json:"rx_bytes,omitempty" yaml:"rx_bytes,omitempty"`
RxErrors uint64 `json:"rx_errors,omitempty" yaml:"rx_errors,omitempty"`
TxPackets uint64 `json:"tx_packets,omitempty" yaml:"tx_packets,omitempty"`
TxDropped uint64 `json:"tx_dropped,omitempty" yaml:"tx_dropped,omitempty"`
RxPackets uint64 `json:"rx_packets,omitempty" yaml:"rx_packets,omitempty"`
TxErrors uint64 `json:"tx_errors,omitempty" yaml:"tx_errors,omitempty"`
TxBytes uint64 `json:"tx_bytes,omitempty" yaml:"tx_bytes,omitempty"`
} `json:"network,omitempty" yaml:"network,omitempty"`
Read time.Time `json:"read,omitempty" yaml:"read,omitempty"`
Networks map[string]NetworkStats `json:"networks,omitempty" yaml:"networks,omitempty"`
MemoryStats struct {
Stats struct {
TotalPgmafault uint64 `json:"total_pgmafault,omitempty" yaml:"total_pgmafault,omitempty"`
Expand Down Expand Up @@ -697,6 +688,18 @@ type Stats struct {
PreCPUStats CPUStats `json:"precpu_stats,omitempty"`
}

// NetworkStats is a stats entry for network stats
type NetworkStats struct {
RxDropped uint64 `json:"rx_dropped,omitempty" yaml:"rx_dropped,omitempty"`
RxBytes uint64 `json:"rx_bytes,omitempty" yaml:"rx_bytes,omitempty"`
RxErrors uint64 `json:"rx_errors,omitempty" yaml:"rx_errors,omitempty"`
TxPackets uint64 `json:"tx_packets,omitempty" yaml:"tx_packets,omitempty"`
TxDropped uint64 `json:"tx_dropped,omitempty" yaml:"tx_dropped,omitempty"`
RxPackets uint64 `json:"rx_packets,omitempty" yaml:"rx_packets,omitempty"`
TxErrors uint64 `json:"tx_errors,omitempty" yaml:"tx_errors,omitempty"`
TxBytes uint64 `json:"tx_bytes,omitempty" yaml:"tx_bytes,omitempty"`
}

// CPUStats is a stats entry for cpu stats
type CPUStats struct {
CPUUsage struct {
Expand Down
46 changes: 25 additions & 21 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1924,16 +1924,18 @@ func TestStatsTimeout(t *testing.T) {
func TestStats(t *testing.T) {
jsonStats1 := `{
"read" : "2015-01-08T22:57:31.547920715Z",
"network" : {
"rx_dropped" : 0,
"rx_bytes" : 648,
"rx_errors" : 0,
"tx_packets" : 8,
"tx_dropped" : 0,
"rx_packets" : 8,
"tx_errors" : 0,
"tx_bytes" : 648
},
"networks" : {
"eth0":{
"rx_dropped" : 0,
"rx_bytes" : 648,
"rx_errors" : 0,
"tx_packets" : 8,
"tx_dropped" : 0,
"rx_packets" : 8,
"tx_errors" : 0,
"tx_bytes" : 648
}
},
"memory_stats" : {
"stats" : {
"total_pgmajfault" : 0,
Expand Down Expand Up @@ -2039,17 +2041,19 @@ func TestStats(t *testing.T) {
// 1 second later, cache is 100
jsonStats2 := `{
"read" : "2015-01-08T22:57:32.547920715Z",
"network" : {
"rx_dropped" : 0,
"rx_bytes" : 648,
"rx_errors" : 0,
"tx_packets" : 8,
"tx_dropped" : 0,
"rx_packets" : 8,
"tx_errors" : 0,
"tx_bytes" : 648
},
"memory_stats" : {
"networks" : {
"eth0":{
"rx_dropped" : 0,
"rx_bytes" : 648,
"rx_errors" : 0,
"tx_packets" : 8,
"tx_dropped" : 0,
"rx_packets" : 8,
"tx_errors" : 0,
"tx_bytes" : 648
}
},
"memory_stats" : {
"stats" : {
"total_pgmajfault" : 0,
"cache" : 100,
Expand Down

0 comments on commit adc42c2

Please sign in to comment.