@@ -31,6 +31,7 @@ import (
31
31
"github.com/golang/glog"
32
32
"github.com/opencontainers/runc/libcontainer"
33
33
"github.com/opencontainers/runc/libcontainer/cgroups"
34
+ "reflect"
34
35
)
35
36
36
37
type CgroupSubsystems struct {
@@ -137,12 +138,33 @@ func GetStats(cgroupManager cgroups.Manager, rootFs string, pid int, ignoreMetri
137
138
138
139
// For backwards compatibility.
139
140
if len (stats .Network .Interfaces ) > 0 {
140
- stats .Network .InterfaceStats = stats .Network .Interfaces [0 ]
141
+ //stats.Network.InterfaceStats = stats.Network.Interfaces[0]
142
+ stats .Network .InterfaceStats = sumNetworkStats (stats )
141
143
}
142
144
143
145
return stats , nil
144
146
}
145
147
148
+ func sumNetworkStats (stats * info.ContainerStats ) info.InterfaceStats {
149
+ interfaceStats := stats .Network .Interfaces [0 ]
150
+ interfaceStats .Name = "ethall"
151
+ t0 := reflect .TypeOf (interfaceStats )
152
+ v0 := reflect .ValueOf (& interfaceStats ).Elem ()
153
+ for i := 1 ; i < len (stats .Network .Interfaces ); i ++ {
154
+ interfaceStatsOfi := stats .Network .Interfaces [i ]
155
+ vi := reflect .ValueOf (interfaceStatsOfi )
156
+
157
+ for k := 1 ; k < t0 .NumField (); k ++ {
158
+ fieldName := t0 .Field (k ).Name
159
+ value0 := v0 .Field (k ).Interface ().(uint64 )
160
+ valuei := vi .Field (k ).Interface ().(uint64 )
161
+ field := v0 .FieldByName (fieldName )
162
+ field .SetUint (value0 + valuei )
163
+ }
164
+ }
165
+ return interfaceStats
166
+ }
167
+
146
168
func networkStatsFromProc (rootFs string , pid int ) ([]info.InterfaceStats , error ) {
147
169
netStatsFile := path .Join (rootFs , "proc" , strconv .Itoa (pid ), "/net/dev" )
148
170
@@ -512,7 +534,8 @@ func setNetworkStats(libcontainerStats *libcontainer.Stats, ret *info.ContainerS
512
534
513
535
// Add to base struct for backwards compatibility.
514
536
if len (ret .Network .Interfaces ) > 0 {
515
- ret .Network .InterfaceStats = ret .Network .Interfaces [0 ]
537
+ //ret.Network.InterfaceStats = ret.Network.Interfaces[0]
538
+ ret .Network .InterfaceStats = sumNetworkStats (ret )
516
539
}
517
540
}
518
541
0 commit comments