mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
net,process[linux]: add process.NetIOCounter and net.NetIOCounterByFile.
This commit is contained in:
parent
85bf0974ed
commit
d680853370
@ -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.
|
||||
|
@ -301,6 +301,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…
x
Reference in New Issue
Block a user