1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-02 15:54:32 +00:00

vendor change

This commit is contained in:
kinarashah
2019-09-25 14:32:29 -07:00
committed by Alena Prokharchyk
parent a40a48add2
commit 5bbe7031a6
607 changed files with 114217 additions and 60063 deletions

View File

@@ -47,13 +47,23 @@ type NetDevLine struct {
// are interface names.
type NetDev map[string]NetDevLine
// NetDev returns kernel/system statistics read from /proc/net/dev.
func (fs FS) NetDev() (NetDev, error) {
return newNetDev(fs.proc.Path("net/dev"))
// NewNetDev returns kernel/system statistics read from /proc/net/dev.
func NewNetDev() (NetDev, error) {
fs, err := NewFS(DefaultMountPoint)
if err != nil {
return nil, err
}
return fs.NewNetDev()
}
// NetDev returns kernel/system statistics read from /proc/[pid]/net/dev.
func (p Proc) NetDev() (NetDev, error) {
// NewNetDev returns kernel/system statistics read from /proc/net/dev.
func (fs FS) NewNetDev() (NetDev, error) {
return newNetDev(fs.Path("net/dev"))
}
// NewNetDev returns kernel/system statistics read from /proc/[pid]/net/dev.
func (p Proc) NewNetDev() (NetDev, error) {
return newNetDev(p.path("net/dev"))
}
@@ -65,7 +75,7 @@ func newNetDev(file string) (NetDev, error) {
}
defer f.Close()
netDev := NetDev{}
nd := NetDev{}
s := bufio.NewScanner(f)
for n := 0; s.Scan(); n++ {
// Skip the 2 header lines.
@@ -73,20 +83,20 @@ func newNetDev(file string) (NetDev, error) {
continue
}
line, err := netDev.parseLine(s.Text())
line, err := nd.parseLine(s.Text())
if err != nil {
return netDev, err
return nd, err
}
netDev[line.Name] = *line
nd[line.Name] = *line
}
return netDev, s.Err()
return nd, s.Err()
}
// parseLine parses a single line from the /proc/net/dev file. Header lines
// must be filtered prior to calling this method.
func (netDev NetDev) parseLine(rawLine string) (*NetDevLine, error) {
func (nd NetDev) parseLine(rawLine string) (*NetDevLine, error) {
parts := strings.SplitN(rawLine, ":", 2)
if len(parts) != 2 {
return nil, errors.New("invalid net/dev line, missing colon")
@@ -175,11 +185,11 @@ func (netDev NetDev) parseLine(rawLine string) (*NetDevLine, error) {
// Total aggregates the values across interfaces and returns a new NetDevLine.
// The Name field will be a sorted comma separated list of interface names.
func (netDev NetDev) Total() NetDevLine {
func (nd NetDev) Total() NetDevLine {
total := NetDevLine{}
names := make([]string, 0, len(netDev))
for _, ifc := range netDev {
names := make([]string, 0, len(nd))
for _, ifc := range nd {
names = append(names, ifc.Name)
total.RxBytes += ifc.RxBytes
total.RxPackets += ifc.RxPackets