Make NetworkStats a pointer to help the callers ignore that stats if it cannot be returned for any reason.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
Vishnu Kannan 2014-07-23 21:18:58 +00:00
parent b2337e4860
commit 2a81a149da
2 changed files with 6 additions and 6 deletions

View File

@ -20,17 +20,17 @@ type NetworkStats struct {
}
// Returns the network statistics for the network interfaces represented by the NetworkRuntimeInfo.
func GetStats(networkState *NetworkState) (NetworkStats, error) {
func GetStats(networkState *NetworkState) (*NetworkStats, error) {
// This can happen if the network runtime information is missing - possible if the container was created by an old version of libcontainer.
if networkState.VethHost == "" {
return NetworkStats{}, nil
return nil, nil
}
data, err := readSysfsNetworkStats(networkState.VethHost)
if err != nil {
return NetworkStats{}, err
return nil, err
}
return NetworkStats{
return &NetworkStats{
RxBytes: data["rx_bytes"],
RxPackets: data["rx_packets"],
RxErrors: data["rx_errors"],

View File

@ -6,6 +6,6 @@ import (
)
type ContainerStats struct {
NetworkStats network.NetworkStats `json:"network_stats, omitempty"`
CgroupStats *cgroups.Stats `json:"cgroup_stats, omitempty"`
NetworkStats *network.NetworkStats `json:"network_stats, omitempty"`
CgroupStats *cgroups.Stats `json:"cgroup_stats, omitempty"`
}