mirror of https://github.com/shirou/gopsutil
commit
ce433bf86e
@ -1,2 +1,3 @@
|
||||
*~
|
||||
#*
|
||||
_obj
|
||||
|
@ -1,13 +1,13 @@
|
||||
// +build darwin
|
||||
|
||||
package gopsutil
|
||||
package common
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func doSysctrl(mib string) ([]string, error) {
|
||||
func DoSysctrl(mib string) ([]string, error) {
|
||||
out, err := exec.Command("/usr/sbin/sysctl", "-n", mib).Output()
|
||||
if err != nil {
|
||||
return []string{}, err
|
@ -1,13 +1,13 @@
|
||||
// +build freebsd
|
||||
|
||||
package gopsutil
|
||||
package common
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func doSysctrl(mib string) ([]string, error) {
|
||||
func DoSysctrl(mib string) ([]string, error) {
|
||||
out, err := exec.Command("/sbin/sysctl", "-n", mib).Output()
|
||||
if err != nil {
|
||||
return []string{}, err
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package cpu
|
||||
|
||||
import (
|
||||
"encoding/json"
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package cpu
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,20 +1,22 @@
|
||||
// +build windows
|
||||
|
||||
package gopsutil
|
||||
package cpu
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
// TODO: Get percpu
|
||||
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
||||
var ret []CPUTimesStat
|
||||
|
||||
var lpIdleTime FILETIME
|
||||
var lpKernelTime FILETIME
|
||||
var lpUserTime FILETIME
|
||||
r, _, _ := procGetSystemTimes.Call(
|
||||
var lpIdleTime common.FILETIME
|
||||
var lpKernelTime common.FILETIME
|
||||
var lpUserTime common.FILETIME
|
||||
r, _, _ := common.ProcGetSystemTimes.Call(
|
||||
uintptr(unsafe.Pointer(&lpIdleTime)),
|
||||
uintptr(unsafe.Pointer(&lpKernelTime)),
|
||||
uintptr(unsafe.Pointer(&lpUserTime)))
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package disk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
@ -0,0 +1,100 @@
|
||||
// +build darwin
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||
var ret []DiskPartitionStat
|
||||
|
||||
count, err := Getfsstat(nil, MntWait)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
fs := make([]Statfs_t, count)
|
||||
_, err = Getfsstat(fs, MntWait)
|
||||
for _, stat := range fs {
|
||||
opts := "rw"
|
||||
if stat.Flags&MntReadOnly != 0 {
|
||||
opts = "ro"
|
||||
}
|
||||
if stat.Flags&MntSynchronous != 0 {
|
||||
opts += ",sync"
|
||||
}
|
||||
if stat.Flags&MntNoExec != 0 {
|
||||
opts += ",noexec"
|
||||
}
|
||||
if stat.Flags&MntNoSuid != 0 {
|
||||
opts += ",nosuid"
|
||||
}
|
||||
if stat.Flags&MntUnion != 0 {
|
||||
opts += ",union"
|
||||
}
|
||||
if stat.Flags&MntAsync != 0 {
|
||||
opts += ",async"
|
||||
}
|
||||
if stat.Flags&MntSuidDir != 0 {
|
||||
opts += ",suiddir"
|
||||
}
|
||||
if stat.Flags&MntSoftDep != 0 {
|
||||
opts += ",softdep"
|
||||
}
|
||||
if stat.Flags&MntNoSymFollow != 0 {
|
||||
opts += ",nosymfollow"
|
||||
}
|
||||
if stat.Flags&MntGEOMJournal != 0 {
|
||||
opts += ",gjounalc"
|
||||
}
|
||||
if stat.Flags&MntMultilabel != 0 {
|
||||
opts += ",multilabel"
|
||||
}
|
||||
if stat.Flags&MntACLs != 0 {
|
||||
opts += ",acls"
|
||||
}
|
||||
if stat.Flags&MntNoATime != 0 {
|
||||
opts += ",noattime"
|
||||
}
|
||||
if stat.Flags&MntClusterRead != 0 {
|
||||
opts += ",nocluster"
|
||||
}
|
||||
if stat.Flags&MntClusterWrite != 0 {
|
||||
opts += ",noclusterw"
|
||||
}
|
||||
if stat.Flags&MntNFS4ACLs != 0 {
|
||||
opts += ",nfs4acls"
|
||||
}
|
||||
d := DiskPartitionStat{
|
||||
Device: common.IntToString(stat.Mntfromname[:]),
|
||||
Mountpoint: common.IntToString(stat.Mntonname[:]),
|
||||
Fstype: common.IntToString(stat.Fstypename[:]),
|
||||
Opts: opts,
|
||||
}
|
||||
ret = append(ret, d)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
|
||||
return nil, common.NotImplementedError
|
||||
}
|
||||
|
||||
func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
|
||||
var _p0 unsafe.Pointer
|
||||
var bufsize uintptr
|
||||
if len(buf) > 0 {
|
||||
_p0 = unsafe.Pointer(&buf[0])
|
||||
bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf))
|
||||
}
|
||||
r0, _, e1 := syscall.Syscall(SYS_GETFSSTAT64, uintptr(_p0), bufsize, uintptr(flags))
|
||||
n = int(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
// +build darwin
|
||||
// +build amd64
|
||||
|
||||
package disk
|
||||
|
||||
const (
|
||||
MntWait = 1
|
||||
MfsNameLen = 15 /* length of fs type name, not inc. nul */
|
||||
MNameLen = 90 /* length of buffer for returned name */
|
||||
|
||||
MFSTYPENAMELEN = 16 /* length of fs type name including null */
|
||||
MAXPATHLEN = 1024
|
||||
MNAMELEN = MAXPATHLEN
|
||||
|
||||
SYS_GETFSSTAT64 = 347
|
||||
)
|
||||
|
||||
type Fsid struct{ val [2]int32 } /* file system id type */
|
||||
type uid_t int32
|
||||
|
||||
// sys/mount.h
|
||||
const (
|
||||
MntReadOnly = 0x00000001 /* read only filesystem */
|
||||
MntSynchronous = 0x00000002 /* filesystem written synchronously */
|
||||
MntNoExec = 0x00000004 /* can't exec from filesystem */
|
||||
MntNoSuid = 0x00000008 /* don't honor setuid bits on fs */
|
||||
MntUnion = 0x00000020 /* union with underlying filesystem */
|
||||
MntAsync = 0x00000040 /* filesystem written asynchronously */
|
||||
MntSuidDir = 0x00100000 /* special handling of SUID on dirs */
|
||||
MntSoftDep = 0x00200000 /* soft updates being done */
|
||||
MntNoSymFollow = 0x00400000 /* do not follow symlinks */
|
||||
MntGEOMJournal = 0x02000000 /* GEOM journal support enabled */
|
||||
MntMultilabel = 0x04000000 /* MAC support for individual objects */
|
||||
MntACLs = 0x08000000 /* ACL support enabled */
|
||||
MntNoATime = 0x10000000 /* disable update of file access time */
|
||||
MntClusterRead = 0x40000000 /* disable cluster read */
|
||||
MntClusterWrite = 0x80000000 /* disable cluster write */
|
||||
MntNFS4ACLs = 0x00000010
|
||||
)
|
||||
|
||||
type Statfs_t struct {
|
||||
Bsize uint32
|
||||
Iosize int32
|
||||
Blocks uint64
|
||||
Bfree uint64
|
||||
Bavail uint64
|
||||
Files uint64
|
||||
Ffree uint64
|
||||
Fsid Fsid
|
||||
Owner uint32
|
||||
Type uint32
|
||||
Flags uint32
|
||||
Fssubtype uint32
|
||||
Fstypename [16]int8
|
||||
Mntonname [1024]int8
|
||||
Mntfromname [1024]int8
|
||||
Reserved [8]uint32
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// +build freebsd
|
||||
// +build amd64
|
||||
|
||||
package gopsutil
|
||||
package disk
|
||||
|
||||
const (
|
||||
MntWait = 1
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package disk
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,6 +1,6 @@
|
||||
// +build freebsd linux darwin
|
||||
|
||||
package gopsutil
|
||||
package disk
|
||||
|
||||
import "syscall"
|
||||
|
@ -1,12 +0,0 @@
|
||||
// +build darwin
|
||||
|
||||
package gopsutil
|
||||
|
||||
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||
|
||||
return nil, NotImplementedError
|
||||
}
|
||||
|
||||
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
|
||||
return nil, NotImplementedError
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// +build linux
|
||||
|
||||
package gopsutil
|
||||
package docker
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package host
|
||||
|
||||
import (
|
||||
"encoding/json"
|
@ -0,0 +1,28 @@
|
||||
// +build freebsd
|
||||
// +build amd64
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs host/types_freebsd.go
|
||||
|
||||
package host
|
||||
|
||||
const (
|
||||
sizeofPtr = 0x8
|
||||
sizeofShort = 0x2
|
||||
sizeofInt = 0x4
|
||||
sizeofLong = 0x8
|
||||
sizeofLongLong = 0x8
|
||||
)
|
||||
|
||||
type (
|
||||
_C_short int16
|
||||
_C_int int32
|
||||
_C_long int64
|
||||
_C_long_long int64
|
||||
)
|
||||
|
||||
type Utmp struct {
|
||||
Line [8]int8
|
||||
Name [16]int8
|
||||
Host [16]int8
|
||||
Time int32
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs types_linux.go
|
||||
|
||||
package host
|
||||
|
||||
const (
|
||||
sizeofPtr = 0x8
|
||||
sizeofShort = 0x2
|
||||
sizeofInt = 0x4
|
||||
sizeofLong = 0x8
|
||||
sizeofLongLong = 0x8
|
||||
)
|
||||
|
||||
type (
|
||||
_C_short int16
|
||||
_C_int int32
|
||||
_C_long int64
|
||||
_C_long_long int64
|
||||
)
|
||||
|
||||
type utmp struct {
|
||||
Type int16
|
||||
Pad_cgo_0 [2]byte
|
||||
Pid int32
|
||||
Line [32]int8
|
||||
Id [4]int8
|
||||
User [32]int8
|
||||
Host [256]int8
|
||||
Exit exit_status
|
||||
Session int32
|
||||
Tv UtTv
|
||||
Addr_v6 [4]int32
|
||||
X__glibc_reserved [20]int8
|
||||
}
|
||||
type exit_status struct {
|
||||
Termination int16
|
||||
Exit int16
|
||||
}
|
||||
type UtTv struct {
|
||||
TvSec int32
|
||||
TvUsec int32
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// +build linux
|
||||
// +build arm
|
||||
|
||||
package host
|
||||
|
||||
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 {
|
||||
Type int16 // Type of login.
|
||||
Pid int32 // Process ID of login process.
|
||||
Line [32]byte // Devicename.
|
||||
ID [4]byte // Inittab ID.
|
||||
User [32]byte // Username.
|
||||
Host [256]byte // Hostname for remote login.
|
||||
Exit exitStatus // Exit status of a process marked
|
||||
Session int32 // Session ID, used for windowing.
|
||||
Tv timeval // Time entry was made.
|
||||
AddrV6 [16]byte // Internet address of remote host.
|
||||
Unused [20]byte // Reserved for future use. // original is 20
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// +build linux
|
||||
|
||||
package gopsutil
|
||||
package host
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package host
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -0,0 +1,40 @@
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs.
|
||||
*/
|
||||
|
||||
package host
|
||||
|
||||
/*
|
||||
#define KERNEL
|
||||
#include <sys/types.h>
|
||||
#include <utmp.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics; for internal use.
|
||||
|
||||
const (
|
||||
sizeofPtr = C.sizeofPtr
|
||||
sizeofShort = C.sizeof_short
|
||||
sizeofInt = C.sizeof_int
|
||||
sizeofLong = C.sizeof_long
|
||||
sizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
type Utmp C.struct_utmp
|
@ -0,0 +1,45 @@
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs.
|
||||
*/
|
||||
|
||||
package host
|
||||
|
||||
/*
|
||||
#define KERNEL
|
||||
#include <sys/types.h>
|
||||
#include <utmp.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics; for internal use.
|
||||
|
||||
const (
|
||||
sizeofPtr = C.sizeofPtr
|
||||
sizeofShort = C.sizeof_short
|
||||
sizeofInt = C.sizeof_int
|
||||
sizeofLong = C.sizeof_long
|
||||
sizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
type utmp C.struct_utmp
|
||||
type exit_status C.struct_exit_status
|
||||
type UtTv struct {
|
||||
TvSec int32
|
||||
TvUsec int32
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
// +build freebsd
|
||||
// +build amd64
|
||||
|
||||
package gopsutil
|
||||
|
||||
const (
|
||||
UTNameSize = 16 /* see MAXLOGNAME in <sys/param.h> */
|
||||
UTLineSize = 8
|
||||
UTHostSize = 16
|
||||
)
|
||||
|
||||
type utmp struct {
|
||||
UtLine [UTLineSize]byte
|
||||
UtName [UTNameSize]byte
|
||||
UtHost [UTHostSize]byte
|
||||
UtTime int32
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// +build linux
|
||||
// +build amd64
|
||||
|
||||
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
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// +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
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package load
|
||||
|
||||
import (
|
||||
"encoding/json"
|
@ -1,13 +1,15 @@
|
||||
// +build darwin
|
||||
|
||||
package gopsutil
|
||||
package load
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
values, err := doSysctrl("vm.loadavg")
|
||||
values, err := common.DoSysctrl("vm.loadavg")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
// +build freebsd
|
||||
|
||||
package gopsutil
|
||||
package load
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
values, err := doSysctrl("vm.loadavg")
|
||||
values, err := common.DoSysctrl("vm.loadavg")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// +build linux
|
||||
|
||||
package gopsutil
|
||||
package load
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package load
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -0,0 +1,13 @@
|
||||
// +build windows
|
||||
|
||||
package load
|
||||
|
||||
import (
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
ret := LoadAvgStat{}
|
||||
|
||||
return &ret, common.NotImplementedError
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package gopsutil
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
ret := LoadAvgStat{}
|
||||
|
||||
return &ret, NotImplementedError
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package mem
|
||||
|
||||
import (
|
||||
"encoding/json"
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package mem
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,14 +1,16 @@
|
||||
// +build windows
|
||||
|
||||
package gopsutil
|
||||
package mem
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
var (
|
||||
procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
|
||||
procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
|
||||
)
|
||||
|
||||
type MEMORYSTATUSEX struct {
|
@ -0,0 +1,37 @@
|
||||
|
||||
DIRS="cpu disk docker host load mem net process"
|
||||
|
||||
GOOS=`uname | tr '[:upper:]' '[:lower:]'`
|
||||
ARCH=`uname -m`
|
||||
|
||||
case $ARCH in
|
||||
amd64)
|
||||
GOARCH="amd64"
|
||||
;;
|
||||
x86_64)
|
||||
GOARCH="amd64"
|
||||
;;
|
||||
i386)
|
||||
GOARCH="386"
|
||||
;;
|
||||
i686)
|
||||
GOARCH="386"
|
||||
;;
|
||||
arm)
|
||||
GOARCH="arm"
|
||||
;;
|
||||
*)
|
||||
echo "unknown arch: $ARCH"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
for DIR in $DIRS
|
||||
do
|
||||
if [ -e ${DIR}/types_${GOOS}.go ]; then
|
||||
echo "// +build $GOOS" > ${DIR}/${DIR}_${GOOS}_${GOARCH}.go
|
||||
echo "// +build $GOARCH" >> ${DIR}/${DIR}_${GOOS}_${GOARCH}.go
|
||||
go tool cgo -godefs ${DIR}/types_${GOOS}.go >> ${DIR}/${DIR}_${GOOS}_${GOARCH}.go
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package net
|
||||
|
||||
import (
|
||||
"encoding/json"
|
@ -1,6 +1,6 @@
|
||||
// +build darwin
|
||||
|
||||
package gopsutil
|
||||
package net
|
||||
|
||||
import (
|
||||
"os/exec"
|
@ -1,6 +1,6 @@
|
||||
// +build freebsd
|
||||
|
||||
package gopsutil
|
||||
package net
|
||||
|
||||
import (
|
||||
"os/exec"
|
@ -1,15 +1,17 @@
|
||||
// +build linux
|
||||
|
||||
package gopsutil
|
||||
package net
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||
filename := "/proc/net/dev"
|
||||
lines, err := readLines(filename)
|
||||
lines, err := common.ReadLines(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package net
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package gopsutil
|
||||
package process
|
||||
|
||||
import (
|
||||
"encoding/json"
|
@ -0,0 +1,236 @@
|
||||
// +build darwin
|
||||
// +build amd64
|
||||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs process/types_darwin.go
|
||||
|
||||
package process
|
||||
|
||||
const (
|
||||
sizeofPtr = 0x8
|
||||
sizeofShort = 0x2
|
||||
sizeofInt = 0x4
|
||||
sizeofLong = 0x8
|
||||
sizeofLongLong = 0x8
|
||||
)
|
||||
|
||||
type (
|
||||
_C_short int16
|
||||
_C_int int32
|
||||
_C_long int64
|
||||
_C_long_long int64
|
||||
)
|
||||
|
||||
type Timespec struct {
|
||||
Sec int64
|
||||
Nsec int64
|
||||
}
|
||||
|
||||
type Timeval struct {
|
||||
Sec int64
|
||||
Usec int32
|
||||
Pad_cgo_0 [4]byte
|
||||
}
|
||||
|
||||
type Rusage struct {
|
||||
Utime Timeval
|
||||
Stime Timeval
|
||||
Maxrss int64
|
||||
Ixrss int64
|
||||
Idrss int64
|
||||
Isrss int64
|
||||
Minflt int64
|
||||
Majflt int64
|
||||
Nswap int64
|
||||
Inblock int64
|
||||
Oublock int64
|
||||
Msgsnd int64
|
||||
Msgrcv int64
|
||||
Nsignals int64
|
||||
Nvcsw int64
|
||||
Nivcsw int64
|
||||
}
|
||||
|
||||
type Rlimit struct {
|
||||
Cur uint64
|
||||
Max uint64
|
||||
}
|
||||
|
||||
type UGid_t uint32
|
||||
|
||||
type KinfoProc struct {
|
||||
Proc ExternProc
|
||||
Eproc Eproc
|
||||
}
|
||||
|
||||
type Eproc struct {
|
||||
Paddr *Proc
|
||||
Sess *Session
|
||||
Pcred Upcred
|
||||
Ucred Uucred
|
||||
Pad_cgo_0 [4]byte
|
||||
Vm Vmspace
|
||||
Ppid int32
|
||||
Pgid int32
|
||||
Jobc int16
|
||||
Pad_cgo_1 [2]byte
|
||||
Tdev int32
|
||||
Tpgid int32
|
||||
Pad_cgo_2 [4]byte
|
||||
Tsess *Session
|
||||
Wmesg [8]int8
|
||||
Xsize int32
|
||||
Xrssize int16
|
||||
Xccount int16
|
||||
Xswrss int16
|
||||
Pad_cgo_3 [2]byte
|
||||
Flag int32
|
||||
Login [12]int8
|
||||
Spare [4]int32
|
||||
Pad_cgo_4 [4]byte
|
||||
}
|
||||
|
||||
type Proc struct{}
|
||||
|
||||
type Session struct{}
|
||||
|
||||
type ucred struct {
|
||||
Link UcredQueue
|
||||
Ref uint64
|
||||
Posix Posix_cred
|
||||
Label *Label
|
||||
Audit Au_session
|
||||
}
|
||||
|
||||
type Uucred struct {
|
||||
Ref int32
|
||||
Uid uint32
|
||||
Ngroups int16
|
||||
Pad_cgo_0 [2]byte
|
||||
Groups [16]uint32
|
||||
}
|
||||
|
||||
type Upcred struct {
|
||||
Pc_lock [72]int8
|
||||
Pc_ucred *ucred
|
||||
P_ruid uint32
|
||||
P_svuid uint32
|
||||
P_rgid uint32
|
||||
P_svgid uint32
|
||||
P_refcnt int32
|
||||
Pad_cgo_0 [4]byte
|
||||
}
|
||||
|
||||
type Vmspace struct {
|
||||
Dummy int32
|
||||
Pad_cgo_0 [4]byte
|
||||
Dummy2 *int8
|
||||
Dummy3 [5]int32
|
||||
Pad_cgo_1 [4]byte
|
||||
Dummy4 [3]*int8
|
||||
}
|
||||
|
||||
type Sigacts struct{}
|
||||
|
||||
type ExternProc struct {
|
||||
P_un [16]byte
|
||||
P_vmspace *Vmspace
|
||||
P_sigacts *Sigacts
|
||||
P_flag int32
|
||||
P_stat int8
|
||||
Pad_cgo_0 [3]byte
|
||||
P_pid int32
|
||||
P_oppid int32
|
||||
P_dupfd int32
|
||||
Pad_cgo_1 [4]byte
|
||||
User_stack *int8
|
||||
Exit_thread *byte
|
||||
P_debugger int32
|
||||
Sigwait int32
|
||||
P_estcpu uint32
|
||||
P_cpticks int32
|
||||
P_pctcpu uint32
|
||||
Pad_cgo_2 [4]byte
|
||||
P_wchan *byte
|
||||
P_wmesg *int8
|
||||
P_swtime uint32
|
||||
P_slptime uint32
|
||||
P_realtimer Itimerval
|
||||
P_rtime Timeval
|
||||
P_uticks uint64
|
||||
P_sticks uint64
|
||||
P_iticks uint64
|
||||
P_traceflag int32
|
||||
Pad_cgo_3 [4]byte
|
||||
P_tracep *Vnode
|
||||
P_siglist int32
|
||||
Pad_cgo_4 [4]byte
|
||||
P_textvp *Vnode
|
||||
P_holdcnt int32
|
||||
P_sigmask uint32
|
||||
P_sigignore uint32
|
||||
P_sigcatch uint32
|
||||
P_priority uint8
|
||||
P_usrpri uint8
|
||||
P_nice int8
|
||||
P_comm [17]int8
|
||||
Pad_cgo_5 [4]byte
|
||||
P_pgrp *Pgrp
|
||||
P_addr *UserStruct
|
||||
P_xstat uint16
|
||||
P_acflag uint16
|
||||
Pad_cgo_6 [4]byte
|
||||
P_ru *Rusage
|
||||
}
|
||||
|
||||
type Itimerval struct {
|
||||
Interval Timeval
|
||||
Value Timeval
|
||||
}
|
||||
|
||||
type Vnode struct{}
|
||||
|
||||
type Pgrp struct{}
|
||||
|
||||
type UserStruct struct{}
|
||||
|
||||
type Au_session struct {
|
||||
Aia_p *AuditinfoAddr
|
||||
Mask AuMask
|
||||
}
|
||||
|
||||
type Posix_cred struct {
|
||||
Uid uint32
|
||||
Ruid uint32
|
||||
Svuid uint32
|
||||
Ngroups int16
|
||||
Pad_cgo_0 [2]byte
|
||||
Groups [16]uint32
|
||||
Rgid uint32
|
||||
Svgid uint32
|
||||
Gmuid uint32
|
||||
Flags int32
|
||||
}
|
||||
|
||||
type Label struct{}
|
||||
|
||||
type AuditinfoAddr struct {
|
||||
Auid uint32
|
||||
Mask AuMask
|
||||
Termid AuTidAddr
|
||||
Asid int32
|
||||
Flags uint64
|
||||
}
|
||||
type AuMask struct {
|
||||
Success uint32
|
||||
Failure uint32
|
||||
}
|
||||
type AuTidAddr struct {
|
||||
Port int32
|
||||
Type uint32
|
||||
Addr [4]uint32
|
||||
}
|
||||
|
||||
type UcredQueue struct {
|
||||
Next *ucred
|
||||
Prev **ucred
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// +build freebsd
|
||||
// +build amd64
|
||||
|
||||
package gopsutil
|
||||
package process
|
||||
|
||||
// copied from sys/sysctl.h
|
||||
const (
|
@ -1,7 +1,7 @@
|
||||
// +build linux
|
||||
// +build amd64
|
||||
|
||||
package gopsutil
|
||||
package process
|
||||
|
||||
const (
|
||||
ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK)
|
@ -1,7 +1,7 @@
|
||||
// +build linux
|
||||
// +build arm
|
||||
|
||||
package gopsutil
|
||||
package process
|
||||
|
||||
const (
|
||||
ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK)
|
@ -1,6 +1,6 @@
|
||||
// +build linux freebsd darwin
|
||||
|
||||
package gopsutil
|
||||
package process
|
||||
|
||||
import (
|
||||
"os"
|
@ -1,6 +1,6 @@
|
||||
// +build linux freebsd
|
||||
|
||||
package gopsutil
|
||||
package process
|
||||
|
||||
import (
|
||||
"os"
|
@ -0,0 +1,157 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs.
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
// +godefs map struct_ [16]byte /* in6_addr */
|
||||
|
||||
package process
|
||||
|
||||
/*
|
||||
#define __DARWIN_UNIX03 0
|
||||
#define KERNEL
|
||||
#define _DARWIN_USE_64_BIT_INODE
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/message.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_var.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/_types/_timeval.h>
|
||||
#include <sys/appleapiopts.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/param.h>
|
||||
#include <bsm/audit.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
struct ucred_queue {
|
||||
struct ucred *tqe_next;
|
||||
struct ucred **tqe_prev;
|
||||
TRACEBUF
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics; for internal use.
|
||||
|
||||
const (
|
||||
sizeofPtr = C.sizeofPtr
|
||||
sizeofShort = C.sizeof_short
|
||||
sizeofInt = C.sizeof_int
|
||||
sizeofLong = C.sizeof_long
|
||||
sizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit
|
||||
|
||||
type UGid_t C.gid_t
|
||||
|
||||
type KinfoProc C.struct_kinfo_proc
|
||||
|
||||
type Eproc C.struct_eproc
|
||||
|
||||
type Proc C.struct_proc
|
||||
|
||||
type Session C.struct_session
|
||||
|
||||
type ucred C.struct_ucred
|
||||
|
||||
type Uucred C.struct__ucred
|
||||
|
||||
type Upcred C.struct__pcred
|
||||
|
||||
type Vmspace C.struct_vmspace
|
||||
|
||||
type Sigacts C.struct_sigacts
|
||||
|
||||
type ExternProc C.struct_extern_proc
|
||||
|
||||
type Itimerval C.struct_itimerval
|
||||
|
||||
type Vnode C.struct_vnode
|
||||
|
||||
type Pgrp C.struct_pgrp
|
||||
|
||||
type UserStruct C.struct_user
|
||||
|
||||
type Au_session C.struct_au_session
|
||||
|
||||
type Posix_cred C.struct_posix_cred
|
||||
|
||||
type Label C.struct_label
|
||||
|
||||
type AuditinfoAddr C.struct_auditinfo_addr
|
||||
type AuMask C.struct_au_mask
|
||||
type AuTidAddr C.struct_au_tid_addr
|
||||
|
||||
// TAILQ(ucred)
|
||||
type UcredQueue C.struct_ucred_queue
|
@ -1,96 +0,0 @@
|
||||
// +build darwin
|
||||
// +build amd64
|
||||
|
||||
package gopsutil
|
||||
|
||||
// copied from sys/sysctl.h
|
||||
const (
|
||||
CTLKern = 1 // "high kernel": proc, limits
|
||||
KernProc = 14 // struct: process entries
|
||||
KernProcPID = 1 // by process id
|
||||
KernProcProc = 8 // only return procs
|
||||
KernProcPathname = 12 // path to executable
|
||||
)
|
||||
|
||||
// copied from sys/user.h
|
||||
type KinfoProc struct {
|
||||
KiStructsize int32
|
||||
KiLayout int32
|
||||
KiArgs int64
|
||||
KiPaddr int64
|
||||
KiAddr int64
|
||||
KiTracep int64
|
||||
KiTextvp int64
|
||||
KiFd int64
|
||||
KiVmspace int64
|
||||
KiWchan int64
|
||||
KiPid int32
|
||||
KiPpid int32
|
||||
KiPgid int32
|
||||
KiTpgid int32
|
||||
KiSid int32
|
||||
KiTsid int32
|
||||
KiJobc [2]byte
|
||||
KiSpareShort1 [2]byte
|
||||
KiTdev int32
|
||||
KiSiglist [16]byte
|
||||
KiSigmask [16]byte
|
||||
KiSigignore [16]byte
|
||||
KiSigcatch [16]byte
|
||||
KiUID int32
|
||||
KiRuid int32
|
||||
KiSvuid int32
|
||||
KiRgid int32
|
||||
KiSvgid int32
|
||||
KiNgroups [2]byte
|
||||
KiSpareShort2 [2]byte
|
||||
KiGroups [64]byte
|
||||
KiSize int64
|
||||
KiRssize int64
|
||||
KiSwrss int64
|
||||
KiTsize int64
|
||||
KiDsize int64
|
||||
KiSsize int64
|
||||
KiXstat [2]byte
|
||||
KiAcflag [2]byte
|
||||
KiPctcpu int32
|
||||
KiEstcpu int32
|
||||
KiSlptime int32
|
||||
KiSwtime int32
|
||||
KiCow int32
|
||||
KiRuntime int64
|
||||
KiStart [16]byte
|
||||
KiChildtime [16]byte
|
||||
KiFlag int64
|
||||
KiKflag int64
|
||||
KiTraceflag int32
|
||||
KiStat [1]byte
|
||||
KiNice [1]byte
|
||||
KiLock [1]byte
|
||||
KiRqindex [1]byte
|
||||
KiOncpu [1]byte
|
||||
KiLastcpu [1]byte
|
||||
KiOcomm [17]byte
|
||||
KiWmesg [9]byte
|
||||
KiLogin [18]byte
|
||||
KiLockname [9]byte
|
||||
KiComm [20]byte
|
||||
KiEmul [17]byte
|
||||
KiSparestrings [68]byte
|
||||
KiSpareints [36]byte
|
||||
KiCrFlags int32
|
||||
KiJid int32
|
||||
KiNumthreads int32
|
||||
KiTid int32
|
||||
KiPri int32
|
||||
KiRusage [144]byte
|
||||
KiRusageCh [144]byte
|
||||
KiPcb int64
|
||||
KiKstack int64
|
||||
KiUdata int64
|
||||
KiTdaddr int64
|
||||
KiSpareptrs [48]byte
|
||||
KiSpareint64s [96]byte
|
||||
KiSflag int64
|
||||
KiTdflags int64
|
||||
}
|
Loading…
Reference in New Issue