net,process[linux]: add process.NetIOCounter and net.NetIOCounterByFile.

pull/137/head
Shirou WAKAYAMA 9 years ago
parent 85bf0974ed
commit d680853370

@ -92,6 +92,15 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
return ret, nil return ret, nil
} }
// NetIOCountersByFile is an method which is added just a compatibility for linux.
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
return NetIOCounters(pernic)
}
func NetFilterCounters() ([]NetFilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for darwin")
}
// NetProtoCounters returns network statistics for the entire system // NetProtoCounters returns network statistics for the entire system
// If protocols is empty then all protocols are returned, otherwise // If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned. // just the protocols in the list are returned.

@ -86,6 +86,15 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
return ret, nil return ret, nil
} }
// NetIOCountersByFile is an method which is added just a compatibility for linux.
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
return NetIOCounters(pernic)
}
func NetFilterCounters() ([]NetFilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for freebsd")
}
// NetProtoCounters returns network statistics for the entire system // NetProtoCounters returns network statistics for the entire system
// If protocols is empty then all protocols are returned, otherwise // If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned. // just the protocols in the list are returned.

@ -17,6 +17,10 @@ import (
// separately. // separately.
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) { func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
filename := common.HostProc("net/dev") filename := common.HostProc("net/dev")
return NetIOCountersByFile(pernic, filename)
}
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
lines, err := common.ReadLines(filename) lines, err := common.ReadLines(filename)
if err != nil { if err != nil {
return nil, err return nil, err

@ -74,6 +74,11 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
return ret, nil return ret, nil
} }
// NetIOCountersByFile is an method which is added just a compatibility for linux.
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
return NetIOCounters(pernic)
}
// Return a list of network connections opened by a process // Return a list of network connections opened by a process
func NetConnections(kind string) ([]NetConnectionStat, error) { func NetConnections(kind string) ([]NetConnectionStat, error) {
var ret []NetConnectionStat var ret []NetConnectionStat
@ -98,6 +103,10 @@ func getAdapterList() (*syscall.IpAdapterInfo, error) {
return a, nil return a, nil
} }
func NetFilterCounters() ([]NetFilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for windows")
}
// NetProtoCounters returns network statistics for the entire system // NetProtoCounters returns network statistics for the entire system
// If protocols is empty then all protocols are returned, otherwise // If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned. // just the protocols in the list are returned.

@ -301,6 +301,10 @@ func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return net.NetConnectionsPid("all", p.Pid) return net.NetConnectionsPid("all", p.Pid)
} }
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) IsRunning() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, common.NotImplementedError return true, common.NotImplementedError
} }

@ -223,6 +223,10 @@ func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, common.NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) IsRunning() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, common.NotImplementedError return true, common.NotImplementedError
} }

@ -235,6 +235,11 @@ func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return net.NetConnectionsPid("all", p.Pid) return net.NetConnectionsPid("all", p.Pid)
} }
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
filename := common.HostProc(strconv.Itoa(int(p.Pid)), "net/dev")
return net.NetIOCountersByFile(pernic, filename)
}
func (p *Process) IsRunning() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, common.NotImplementedError return true, common.NotImplementedError
} }

@ -243,6 +243,10 @@ func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return nil, common.NotImplementedError return nil, common.NotImplementedError
} }
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) IsRunning() (bool, error) { func (p *Process) IsRunning() (bool, error) {
return true, common.NotImplementedError return true, common.NotImplementedError
} }

Loading…
Cancel
Save