mirror of https://github.com/shirou/gopsutil
Merge branch 'master' of github.com:shirou/gopsutil
commit
c8ee4d9b07
@ -0,0 +1,27 @@
|
|||||||
|
// +build linux
|
||||||
|
// +build arm
|
||||||
|
|
||||||
|
package gopsutil
|
||||||
|
|
||||||
|
type exitStatus struct {
|
||||||
|
Etermination int16 // Process termination status.
|
||||||
|
Eexit int16 // Process exit status.
|
||||||
|
}
|
||||||
|
type timeval struct {
|
||||||
|
TvSec uint32 // Seconds.
|
||||||
|
TvUsec uint32 // Microseconds.
|
||||||
|
}
|
||||||
|
|
||||||
|
type utmp struct {
|
||||||
|
UtType int16 // Type of login.
|
||||||
|
UtPid int32 // Process ID of login process.
|
||||||
|
UtLine [32]byte // Devicename.
|
||||||
|
UtID [4]byte // Inittab ID.
|
||||||
|
UtUser [32]byte // Username.
|
||||||
|
UtHost [256]byte // Hostname for remote login.
|
||||||
|
UtExit exitStatus // Exit status of a process marked
|
||||||
|
UtSession int32 // Session ID, used for windowing.
|
||||||
|
UtTv timeval // Time entry was made.
|
||||||
|
UtAddrV6 [16]byte // Internet address of remote host.
|
||||||
|
Unused [20]byte // Reserved for future use. // original is 20
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
// +build freebsd
|
||||||
|
|
||||||
|
package gopsutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
|
return nil, errors.New("not implemented yet")
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package gopsutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
modiphlpapi = NewLazyDLL("iphlpapi.dll")
|
||||||
|
procGetExtendedTcpTable = modiphlpapi.NewProc("GetExtendedTcpTable")
|
||||||
|
procGetExtendedUdpTable = modiphlpapi.NewProc("GetExtendedUdpTable")
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TCP_TABLE_BASIC_LISTENER = iota
|
||||||
|
TCP_TABLE_BASIC_CONNECTIONS
|
||||||
|
TCP_TABLE_BASIC_ALL
|
||||||
|
TCP_TABLE_OWNER_PID_LISTENER
|
||||||
|
TCP_TABLE_OWNER_PID_CONNECTIONS
|
||||||
|
TCP_TABLE_OWNER_PID_ALL
|
||||||
|
TCP_TABLE_OWNER_MODULE_LISTENER
|
||||||
|
TCP_TABLE_OWNER_MODULE_CONNECTIONS
|
||||||
|
TCP_TABLE_OWNER_MODULE_ALL
|
||||||
|
)
|
||||||
|
|
||||||
|
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
|
ifs, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ai, err := getAdapterList()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var ret []NetIOCountersStat
|
||||||
|
|
||||||
|
for _, ifi := range ifs {
|
||||||
|
name := ifi.Name
|
||||||
|
for ; ai != nil; ai = ai.Next {
|
||||||
|
name = bytePtrToString(&ai.Description[0])
|
||||||
|
c := NetIOCountersStat{
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
|
||||||
|
row := syscall.MibIfRow{Index: ai.Index}
|
||||||
|
e := syscall.GetIfEntry(&row)
|
||||||
|
if e != nil {
|
||||||
|
return nil, os.NewSyscallError("GetIfEntry", e)
|
||||||
|
}
|
||||||
|
c.BytesSent = uint64(row.OutOctets)
|
||||||
|
c.BytesRecv = uint64(row.InOctets)
|
||||||
|
c.PacketsSent = uint64(row.OutUcastPkts)
|
||||||
|
c.PacketsRecv = uint64(row.InUcastPkts)
|
||||||
|
c.Errin = uint64(row.InErrors)
|
||||||
|
c.Errout = uint64(row.OutErrors)
|
||||||
|
c.Dropin = uint64(row.InDiscards)
|
||||||
|
c.Dropout = uint64(row.OutDiscards)
|
||||||
|
|
||||||
|
ret = append(ret, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a list of network connections opened by a process
|
||||||
|
func NetConnections(kind string) ([]NetConnectionStat, error) {
|
||||||
|
var ret []NetConnectionStat
|
||||||
|
|
||||||
|
return ret, erros.New("not implemented yet")
|
||||||
|
}
|
||||||
|
|
||||||
|
// borrowed from src/pkg/net/interface_windows.go
|
||||||
|
func getAdapterList() (*syscall.IpAdapterInfo, error) {
|
||||||
|
b := make([]byte, 1000)
|
||||||
|
l := uint32(len(b))
|
||||||
|
a := (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
|
||||||
|
err := syscall.GetAdaptersInfo(a, &l)
|
||||||
|
if err == syscall.ERROR_BUFFER_OVERFLOW {
|
||||||
|
b = make([]byte, l)
|
||||||
|
a = (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0]))
|
||||||
|
err = syscall.GetAdaptersInfo(a, &l)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, os.NewSyscallError("GetAdaptersInfo", err)
|
||||||
|
}
|
||||||
|
return a, nil
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
// +build linux
|
||||||
|
// +build arm
|
||||||
|
|
||||||
|
package gopsutil
|
||||||
|
|
||||||
|
const (
|
||||||
|
CLOCK_TICKS = 100 // C.sysconf(C._SC_CLK_TCK)
|
||||||
|
PAGESIZE = 4096 // C.sysconf(C._SC_PAGE_SIZE)
|
||||||
|
)
|
Loading…
Reference in New Issue