MCPcopy Index your code
hub / github.com/opencontainers/runc / getNetworkInterfaceStats

Function getNetworkInterfaceStats

libcontainer/network_linux.go:45–78  ·  view source on GitHub ↗

Returns the network statistics for the network interfaces represented by the NetworkRuntimeInfo.

(interfaceName string)

Source from the content-addressed store, hash-verified

43
44// Returns the network statistics for the network interfaces represented by the NetworkRuntimeInfo.
45func getNetworkInterfaceStats(interfaceName string) (*types.NetworkInterface, error) {
46 out := &types.NetworkInterface{Name: interfaceName}
47 // This can happen if the network runtime information is missing - possible if the
48 // container was created by an old version of libcontainer.
49 if interfaceName == "" {
50 return out, nil
51 }
52 type netStatsPair struct {
53 // Where to write the output.
54 Out *uint64
55 // The network stats file to read.
56 File string
57 }
58 // Ingress for host veth is from the container. Hence tx_bytes stat on the host veth is actually number of bytes received by the container.
59 netStats := []netStatsPair{
60 {Out: &out.RxBytes, File: "tx_bytes"},
61 {Out: &out.RxPackets, File: "tx_packets"},
62 {Out: &out.RxErrors, File: "tx_errors"},
63 {Out: &out.RxDropped, File: "tx_dropped"},
64
65 {Out: &out.TxBytes, File: "rx_bytes"},
66 {Out: &out.TxPackets, File: "rx_packets"},
67 {Out: &out.TxErrors, File: "rx_errors"},
68 {Out: &out.TxDropped, File: "rx_dropped"},
69 }
70 for _, netStat := range netStats {
71 data, err := readSysfsNetworkStats(interfaceName, netStat.File)
72 if err != nil {
73 return nil, err
74 }
75 *(netStat.Out) = data
76 }
77 return out, nil
78}
79
80// Reads the specified statistics available under /sys/class/net/<EthInterface>/statistics
81func readSysfsNetworkStats(ethInterface, statsFile string) (uint64, error) {

Callers 1

StatsMethod · 0.85

Calls 1

readSysfsNetworkStatsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…