Merge pull request #137 from shirou/process/add_netiocounter_for_linux

[WIP] net,process[linux]: add process.NetIOCounter and net.NetIOCounterByFile.
pull/141/head
shirou 9 years ago
commit 9d8191d6a6

@ -92,6 +92,15 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
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
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.

@ -86,6 +86,15 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
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
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.

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

@ -74,6 +74,11 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
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
func NetConnections(kind string) ([]NetConnectionStat, error) {
var ret []NetConnectionStat
@ -98,6 +103,10 @@ func getAdapterList() (*syscall.IpAdapterInfo, error) {
return a, nil
}
func NetFilterCounters() ([]NetFilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for windows")
}
// NetProtoCounters returns network statistics for the entire system
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.

@ -302,6 +302,10 @@ func (p *Process) Connections() ([]net.NetConnectionStat, error) {
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) {
return true, common.NotImplementedError
}

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

@ -235,6 +235,11 @@ func (p *Process) Connections() ([]net.NetConnectionStat, error) {
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) {
return true, common.NotImplementedError
}

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

Loading…
Cancel
Save