Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
d511748b
G
Gopsutil
项目概览
Canread
/
Gopsutil
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gopsutil
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d511748b
编写于
4月 30, 2014
作者:
S
Shirou WAKAYAMA
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
golint on Linux
上级
9a32bb9b
变更
27
隐藏空白更改
内联
并排
Showing
27 changed file
with
230 addition
and
231 deletion
+230
-231
common.go
common.go
+3
-4
common_freebsd.go
common_freebsd.go
+1
-1
cpu.go
cpu.go
+13
-13
cpu_freebsd.go
cpu_freebsd.go
+8
-8
cpu_linux.go
cpu_linux.go
+9
-9
cpu_test.go
cpu_test.go
+1
-1
disk_freebsd.go
disk_freebsd.go
+4
-4
disk_freebsd_amd64.go
disk_freebsd_amd64.go
+22
-22
disk_linux.go
disk_linux.go
+5
-5
disk_unix.go
disk_unix.go
+2
-2
disk_windows.go
disk_windows.go
+1
-1
host_freebsd.go
host_freebsd.go
+2
-2
host_freebsd_amd64.go
host_freebsd_amd64.go
+4
-4
host_linux.go
host_linux.go
+6
-6
host_linux_amd64.go
host_linux_amd64.go
+16
-16
load_freebsd.go
load_freebsd.go
+1
-1
mem_linux.go
mem_linux.go
+2
-2
net.go
net.go
+1
-1
net_linux.go
net_linux.go
+11
-11
process.go
process.go
+1
-1
process_freebsd.go
process_freebsd.go
+1
-1
process_freebsd_amd64.go
process_freebsd_amd64.go
+80
-80
process_linux.go
process_linux.go
+6
-6
process_posix.go
process_posix.go
+12
-12
process_test.go
process_test.go
+12
-12
process_test_posix.go
process_test_posix.go
+4
-4
process_windows.go
process_windows.go
+2
-2
未找到文件。
common.go
浏览文件 @
d511748b
...
...
@@ -13,7 +13,7 @@ import (
"strings"
)
// Read contents from file and split by new line.
// Read
Lines read
contents from file and split by new line.
func
ReadLines
(
filename
string
)
([]
string
,
error
)
{
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
...
...
@@ -21,7 +21,7 @@ func ReadLines(filename string) ([]string, error) {
}
defer
f
.
Close
()
ret
:=
make
([]
string
,
0
)
var
ret
[]
string
r
:=
bufio
.
NewReader
(
f
)
line
,
err
:=
r
.
ReadString
(
'\n'
)
...
...
@@ -52,9 +52,8 @@ func byteToString(orig []byte) string {
}
if
n
==
-
1
{
return
string
(
orig
)
}
else
{
return
string
(
orig
[
l
:
n
])
}
return
string
(
orig
[
l
:
n
])
}
// Parse to int32 without error
...
...
common_freebsd.go
浏览文件 @
d511748b
...
...
@@ -7,7 +7,7 @@ import (
"strings"
)
func
do
_s
ysctrl
(
mib
string
)
([]
string
,
error
)
{
func
do
S
ysctrl
(
mib
string
)
([]
string
,
error
)
{
out
,
err
:=
exec
.
Command
(
"/sbin/sysctl"
,
"-n"
,
mib
)
.
Output
()
if
err
!=
nil
{
return
[]
string
{},
err
...
...
cpu.go
浏览文件 @
d511748b
...
...
@@ -5,20 +5,20 @@ import (
)
type
CPUTimesStat
struct
{
C
pu
string
`json:"cpu"`
User
float32
`json:"user"`
System
float32
`json:"system"`
Idle
float32
`json:"idle"`
Nice
float32
`json:"nice"`
Iowait
float32
`json:"iowait"`
Irq
float32
`json:"irq"`
Softirq
float32
`json:"softirq"`
Steal
float32
`json:"steal"`
Guest
float32
`json:"guest"`
Guest
_n
ice
float32
`json:"guest_nice"`
Stolen
float32
`json:"stolen"`
C
PU
string
`json:"cpu"`
User
float32
`json:"user"`
System
float32
`json:"system"`
Idle
float32
`json:"idle"`
Nice
float32
`json:"nice"`
Iowait
float32
`json:"iowait"`
Irq
float32
`json:"irq"`
Softirq
float32
`json:"softirq"`
Steal
float32
`json:"steal"`
Guest
float32
`json:"guest"`
Guest
N
ice
float32
`json:"guest_nice"`
Stolen
float32
`json:"stolen"`
}
func
C
pu
Counts
(
logical
bool
)
(
int
,
error
)
{
func
C
PU
Counts
(
logical
bool
)
(
int
,
error
)
{
return
runtime
.
NumCPU
(),
nil
}
cpu_freebsd.go
浏览文件 @
d511748b
...
...
@@ -23,20 +23,20 @@ const (
// TODO: get per cpus
func
CPUTimes
(
percpu
bool
)
([]
CPUTimesStat
,
error
)
{
ret
:=
make
([]
CPU_TimesStat
,
0
)
var
ret
[]
CPU_TimesStat
cpu
_time
,
err
:=
do_s
ysctrl
(
"kern.cp_time"
)
cpu
Time
,
err
:=
doS
ysctrl
(
"kern.cp_time"
)
if
err
!=
nil
{
return
ret
,
err
}
user
,
_
:=
strconv
.
ParseFloat
(
cpu
_t
ime
[
CP_USER
],
32
)
nice
,
_
:=
strconv
.
ParseFloat
(
cpu
_t
ime
[
CP_NICE
],
32
)
sys
,
_
:=
strconv
.
ParseFloat
(
cpu
_t
ime
[
CP_SYS
],
32
)
idle
,
_
:=
strconv
.
ParseFloat
(
cpu
_t
ime
[
CP_IDLE
],
32
)
intr
,
_
:=
strconv
.
ParseFloat
(
cpu
_t
ime
[
CP_INTR
],
32
)
user
,
_
:=
strconv
.
ParseFloat
(
cpu
T
ime
[
CP_USER
],
32
)
nice
,
_
:=
strconv
.
ParseFloat
(
cpu
T
ime
[
CP_NICE
],
32
)
sys
,
_
:=
strconv
.
ParseFloat
(
cpu
T
ime
[
CP_SYS
],
32
)
idle
,
_
:=
strconv
.
ParseFloat
(
cpu
T
ime
[
CP_IDLE
],
32
)
intr
,
_
:=
strconv
.
ParseFloat
(
cpu
T
ime
[
CP_INTR
],
32
)
c
:=
CPU
_
TimesStat
{
c
:=
CPUTimesStat
{
User
:
float32
(
user
/
CLOCKS_PER_SEC
),
Nice
:
float32
(
nice
/
CLOCKS_PER_SEC
),
System
:
float32
(
sys
/
CLOCKS_PER_SEC
),
...
...
cpu_linux.go
浏览文件 @
d511748b
...
...
@@ -8,8 +8,8 @@ import (
"strings"
)
func
C
pu_times
(
percpu
bool
)
([]
CPU_
TimesStat
,
error
)
{
ret
:=
make
([]
CPU_TimesStat
,
0
)
func
C
PUTimes
(
percpu
bool
)
([]
CPU
TimesStat
,
error
)
{
var
ret
[]
CPUTimesStat
filename
:=
"/proc/stat"
lines
,
_
:=
ReadLines
(
filename
)
...
...
@@ -24,12 +24,12 @@ func Cpu_times(percpu bool) ([]CPU_TimesStat, error) {
return
ret
,
nil
}
func
parseStatLine
(
line
string
)
(
CPU
_
TimesStat
,
error
)
{
func
parseStatLine
(
line
string
)
(
CPUTimesStat
,
error
)
{
fields
:=
strings
.
Fields
(
line
)
if
strings
.
HasPrefix
(
fields
[
0
],
"cpu"
)
==
false
{
// return CPU
_
TimesStat{}, e
return
CPU
_
TimesStat
{},
errors
.
New
(
"not contain cpu"
)
// return CPUTimesStat{}, e
return
CPUTimesStat
{},
errors
.
New
(
"not contain cpu"
)
}
cpu
:=
fields
[
0
]
...
...
@@ -44,8 +44,8 @@ func parseStatLine(line string) (CPU_TimesStat, error) {
irq
,
_
:=
strconv
.
ParseFloat
(
fields
[
6
],
32
)
softirq
,
_
:=
strconv
.
ParseFloat
(
fields
[
7
],
32
)
stolen
,
_
:=
strconv
.
ParseFloat
(
fields
[
8
],
32
)
ct
:=
CPU
_
TimesStat
{
C
pu
:
cpu
,
ct
:=
CPUTimesStat
{
C
PU
:
cpu
,
User
:
float32
(
user
),
Nice
:
float32
(
nice
),
System
:
float32
(
system
),
...
...
@@ -64,8 +64,8 @@ func parseStatLine(line string) (CPU_TimesStat, error) {
ct
.
Guest
=
float32
(
guest
)
}
if
len
(
fields
)
>
11
{
// Linux >= 3.2.0
guest
_n
ice
,
_
:=
strconv
.
ParseFloat
(
fields
[
11
],
32
)
ct
.
Guest
_nice
=
float32
(
guest_n
ice
)
guest
N
ice
,
_
:=
strconv
.
ParseFloat
(
fields
[
11
],
32
)
ct
.
Guest
Nice
=
float32
(
guestN
ice
)
}
return
ct
,
nil
...
...
cpu_test.go
浏览文件 @
d511748b
...
...
@@ -21,7 +21,7 @@ func TestCpu_times(t *testing.T) {
}
func
TestCpu_counts
(
t
*
testing
.
T
)
{
v
,
err
:=
C
pu
Counts
(
true
)
v
,
err
:=
C
PU
Counts
(
true
)
if
err
!=
nil
{
t
.
Errorf
(
"error %v"
,
err
)
}
...
...
disk_freebsd.go
浏览文件 @
d511748b
...
...
@@ -9,7 +9,7 @@ import (
)
func
DiskPartitions
(
all
bool
)
([]
DiskPartitionStat
,
error
)
{
ret
:=
make
([]
Disk_partitionStat
,
0
)
var
ret
[]
Disk_partitionStat
// get length
count
,
err
:=
syscall
.
Getfsstat
(
nil
,
MNT_WAIT
)
...
...
@@ -72,8 +72,8 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
}
d
:=
Disk_partitionStat
{
Mountpoint
:
byteToString
(
stat
.
F
_m
ntonname
[
:
]),
Fstype
:
byteToString
(
stat
.
F
_f
stypename
[
:
]),
Mountpoint
:
byteToString
(
stat
.
F
M
ntonname
[
:
]),
Fstype
:
byteToString
(
stat
.
F
F
stypename
[
:
]),
Opts
:
opts
,
}
ret
=
append
(
ret
,
d
)
...
...
@@ -83,7 +83,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
}
func
DiskIOCounters
()
(
map
[
string
]
DiskIOCountersStat
,
error
)
{
ret
:=
make
(
map
[
string
]
Disk
_IO_
CountersStat
,
0
)
ret
:=
make
(
map
[
string
]
Disk
IO
CountersStat
,
0
)
return
ret
,
errors
.
New
(
"not implemented yet"
)
}
...
...
disk_freebsd_amd64.go
浏览文件 @
d511748b
...
...
@@ -30,26 +30,26 @@ const (
)
type
Statfs
struct
{
F
_v
ersion
uint32
/* structure version number */
F
_t
ype
uint32
/* type of filesystem */
F
_f
lags
uint64
/* copy of mount exported flags */
F
_b
size
uint64
/* filesystem fragment size */
F
_i
osize
uint64
/* optimal transfer block size */
F
_b
locks
uint64
/* total data blocks in filesystem */
F
_b
free
uint64
/* free blocks in filesystem */
F
_b
avail
int64
/* free blocks avail to non-superuser */
F
_f
iles
uint64
/* total file nodes in filesystem */
F
_f
free
int64
/* free nodes avail to non-superuser */
F
_s
yncwrites
uint64
/* count of sync writes since mount */
F
_a
syncwrites
uint64
/* count of async writes since mount */
F
_s
yncreads
uint64
/* count of sync reads since mount */
F
_a
syncreads
uint64
/* count of async reads since mount */
F
_s
pare
[
10
]
uint64
/* unused spare */
F
_n
amemax
uint32
/* maximum filename length */
F
_o
wner
uint32
/* user that mounted the filesystem */
F
_f
sid
int32
/* filesystem id */
F
_c
harspare
[
80
]
byte
/* spare string space */
F
_f
stypename
[
MFSNAMELEN
]
byte
/* filesystem type name */
F
_m
ntfromname
[
MNAMELEN
]
byte
/* mounted filesystem */
F
_m
ntonname
[
MNAMELEN
]
byte
/* directory on which mounted */
F
V
ersion
uint32
/* structure version number */
F
T
ype
uint32
/* type of filesystem */
F
F
lags
uint64
/* copy of mount exported flags */
F
B
size
uint64
/* filesystem fragment size */
F
I
osize
uint64
/* optimal transfer block size */
F
B
locks
uint64
/* total data blocks in filesystem */
F
B
free
uint64
/* free blocks in filesystem */
F
B
avail
int64
/* free blocks avail to non-superuser */
F
F
iles
uint64
/* total file nodes in filesystem */
F
F
free
int64
/* free nodes avail to non-superuser */
F
S
yncwrites
uint64
/* count of sync writes since mount */
F
A
syncwrites
uint64
/* count of async writes since mount */
F
S
yncreads
uint64
/* count of sync reads since mount */
F
A
syncreads
uint64
/* count of async reads since mount */
F
S
pare
[
10
]
uint64
/* unused spare */
F
N
amemax
uint32
/* maximum filename length */
F
O
wner
uint32
/* user that mounted the filesystem */
F
F
sid
int32
/* filesystem id */
F
C
harspare
[
80
]
byte
/* spare string space */
F
F
stypename
[
MFSNAMELEN
]
byte
/* filesystem type name */
F
M
ntfromname
[
MNAMELEN
]
byte
/* mounted filesystem */
F
M
ntonname
[
MNAMELEN
]
byte
/* directory on which mounted */
}
disk_linux.go
浏览文件 @
d511748b
...
...
@@ -14,7 +14,7 @@ const (
// Get disk partitions.
// should use setmntent(3) but this implement use /etc/mtab file
func
DiskPartitions
(
all
bool
)
([]
DiskPartitionStat
,
error
)
{
ret
:=
make
([]
Disk_partitionStat
,
0
)
var
ret
[]
DiskPartitionStat
filename
:=
"/etc/mtab"
lines
,
err
:=
ReadLines
(
filename
)
...
...
@@ -24,7 +24,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
for
_
,
line
:=
range
lines
{
fields
:=
strings
.
Fields
(
line
)
d
:=
Disk
_p
artitionStat
{
d
:=
Disk
P
artitionStat
{
Mountpoint
:
fields
[
1
],
Fstype
:
fields
[
2
],
Opts
:
fields
[
3
],
...
...
@@ -36,7 +36,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
}
func
DiskIOCounters
()
(
map
[
string
]
DiskIOCountersStat
,
error
)
{
ret
:=
make
(
map
[
string
]
Disk
_IO_
CountersStat
,
0
)
ret
:=
make
(
map
[
string
]
Disk
IO
CountersStat
,
0
)
// determine partitions we want to look for
filename
:=
"/proc/partitions"
...
...
@@ -44,7 +44,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
if
err
!=
nil
{
return
ret
,
err
}
partitions
:=
make
([]
string
,
0
)
var
partitions
[]
string
for
_
,
line
:=
range
lines
[
2
:
]
{
fields
:=
strings
.
Fields
(
line
)
...
...
@@ -76,7 +76,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
wbytes
:=
parseUint64
(
fields
[
9
])
wtime
:=
parseUint64
(
fields
[
10
])
if
stringContains
(
partitions
,
name
)
{
d
:=
Disk
_IO_
CountersStat
{
d
:=
Disk
IO
CountersStat
{
Name
:
name
,
ReadBytes
:
rbytes
*
SECTOR_SIZE
,
WriteBytes
:
wbytes
*
SECTOR_SIZE
,
...
...
disk_unix.go
浏览文件 @
d511748b
...
...
@@ -8,12 +8,12 @@ func DiskUsage(path string) (DiskUsageStat, error) {
stat
:=
syscall
.
Statfs_t
{}
err
:=
syscall
.
Statfs
(
path
,
&
stat
)
if
err
!=
nil
{
return
Disk
_u
sageStat
{
Path
:
path
},
err
return
Disk
U
sageStat
{
Path
:
path
},
err
}
bsize
:=
stat
.
Bsize
/
512
ret
:=
Disk
_u
sageStat
{
ret
:=
Disk
U
sageStat
{
Path
:
path
,
Total
:
(
uint64
(
stat
.
Blocks
)
*
uint64
(
bsize
))
>>
1
,
Free
:
(
uint64
(
stat
.
Bfree
)
*
uint64
(
bsize
))
>>
1
,
...
...
disk_windows.go
浏览文件 @
d511748b
...
...
@@ -46,7 +46,7 @@ func DiskUsage(path string) (DiskUsageStat, error) {
}
func
DiskPartitions
(
all
bool
)
([]
DiskPartitionStat
,
error
)
{
ret
:=
make
([]
DiskPartitionStat
,
0
)
var
ret
[]
DiskPartitionStat
lpBuffer
:=
make
([]
byte
,
254
)
diskret
,
_
,
err
:=
procGetLogicalDriveStringsW
.
Call
(
uintptr
(
len
(
lpBuffer
)),
...
...
host_freebsd.go
浏览文件 @
d511748b
...
...
@@ -25,7 +25,7 @@ func HostInfo() (HostInfoStat, error) {
}
func
BootTime
()
(
int64
,
error
)
{
values
,
err
:=
do
_s
ysctrl
(
"kern.boottime"
)
values
,
err
:=
do
S
ysctrl
(
"kern.boottime"
)
if
err
!=
nil
{
return
0
,
err
}
...
...
@@ -42,7 +42,7 @@ func BootTime() (int64, error) {
func
Users
()
([]
UserStat
,
error
)
{
utmpfile
:=
"/var/run/utmp"
ret
:=
make
([]
UserStat
,
0
)
var
ret
[]
UserStat
file
,
err
:=
os
.
Open
(
utmpfile
)
if
err
!=
nil
{
...
...
host_freebsd_amd64.go
浏览文件 @
d511748b
...
...
@@ -10,8 +10,8 @@ const (
)
type
utmp
struct
{
Ut
_l
ine
[
UT_LINESIZE
]
byte
Ut
_n
ame
[
UT_NAMESIZE
]
byte
Ut
_h
ost
[
UT_HOSTSIZE
]
byte
Ut
_t
ime
int32
Ut
L
ine
[
UT_LINESIZE
]
byte
Ut
N
ame
[
UT_NAMESIZE
]
byte
Ut
H
ost
[
UT_HOSTSIZE
]
byte
Ut
T
ime
int32
}
host_linux.go
浏览文件 @
d511748b
...
...
@@ -23,7 +23,7 @@ func HostInfo() (HostInfoStat, error) {
return
ret
,
nil
}
func
Boot
_t
ime
()
(
int64
,
error
)
{
func
Boot
T
ime
()
(
int64
,
error
)
{
sysinfo
:=
&
syscall
.
Sysinfo_t
{}
if
err
:=
syscall
.
Sysinfo
(
sysinfo
);
err
!=
nil
{
return
0
,
err
...
...
@@ -33,7 +33,7 @@ func Boot_time() (int64, error) {
func
Users
()
([]
UserStat
,
error
)
{
utmpfile
:=
"/var/run/utmp"
ret
:=
make
([]
UserStat
,
0
)
var
ret
[]
UserStat
file
,
err
:=
os
.
Open
(
utmpfile
)
if
err
!=
nil
{
...
...
@@ -59,10 +59,10 @@ func Users() ([]UserStat, error) {
continue
}
user
:=
UserStat
{
User
:
byteToString
(
u
.
Ut
_u
ser
[
:
]),
Terminal
:
byteToString
(
u
.
Ut
_l
ine
[
:
]),
Host
:
byteToString
(
u
.
Ut
_h
ost
[
:
]),
Started
:
int
(
u
.
Ut
_tv
.
Tv_s
ec
),
User
:
byteToString
(
u
.
Ut
U
ser
[
:
]),
Terminal
:
byteToString
(
u
.
Ut
L
ine
[
:
]),
Host
:
byteToString
(
u
.
Ut
H
ost
[
:
]),
Started
:
int
(
u
.
Ut
Tv
.
TvS
ec
),
}
ret
=
append
(
ret
,
user
)
}
...
...
host_linux_amd64.go
浏览文件 @
d511748b
...
...
@@ -3,25 +3,25 @@
package
gopsutil
type
exit
_s
tatus
struct
{
E
_
termination
int16
// Process termination status.
E
_
exit
int16
// Process exit status.
type
exit
S
tatus
struct
{
Etermination
int16
// Process termination status.
Eexit
int16
// Process exit status.
}
type
timeval
struct
{
Tv
_s
ec
uint32
// Seconds.
Tv
_u
sec
uint32
// Microseconds.
Tv
S
ec
uint32
// Seconds.
Tv
U
sec
uint32
// Microseconds.
}
type
utmp
struct
{
Ut
_type
int16
// Type of login.
Ut
_pid
int32
// Process ID of login process.
Ut
_line
[
32
]
byte
// Devicename.
Ut
_id
[
4
]
byte
// Inittab ID.
Ut
_user
[
32
]
byte
// Username.
Ut
_host
[
256
]
byte
// Hostname for remote login.
Ut
_exit
exit_s
tatus
// Exit status of a process marked
Ut
_session
int32
// Session ID, used for windowing.
Ut
_tv
timeval
// Time entry was made.
Ut
_addr_v6
[
16
]
byte
// Internet address of remote host.
Unused
[
20
]
byte
// Reserved for future use. // original is 20
Ut
Type
int16
// Type of login.
Ut
Pid
int32
// Process ID of login process.
Ut
Line
[
32
]
byte
// Devicename.
Ut
ID
[
4
]
byte
// Inittab ID.
Ut
User
[
32
]
byte
// Username.
Ut
Host
[
256
]
byte
// Hostname for remote login.
Ut
Exit
exitS
tatus
// Exit status of a process marked
Ut
Session
int32
// Session ID, used for windowing.
Ut
Tv
timeval
// Time entry was made.
Ut
AddrV6
[
16
]
byte
// Internet address of remote host.
Unused
[
20
]
byte
// Reserved for future use. // original is 20
}
load_freebsd.go
浏览文件 @
d511748b
...
...
@@ -7,7 +7,7 @@ import (
)
func
LoadAvg
()
(
LoadAvgStat
,
error
)
{
values
,
err
:=
do
_s
ysctrl
(
"vm.loadavg"
)
values
,
err
:=
do
S
ysctrl
(
"vm.loadavg"
)
if
err
!=
nil
{
return
LoadAvgStat
{},
err
}
...
...
mem_linux.go
浏览文件 @
d511748b
...
...
@@ -7,7 +7,7 @@ import (
)
func
VirtualMemory
()
(
VirtualMemoryStat
,
error
)
{
ret
:=
Virtual
_m
emoryStat
{}
ret
:=
Virtual
M
emoryStat
{}
sysinfo
:=
&
syscall
.
Sysinfo_t
{}
if
err
:=
syscall
.
Sysinfo
(
sysinfo
);
err
!=
nil
{
...
...
@@ -36,7 +36,7 @@ func VirtualMemory() (VirtualMemoryStat, error) {
}
func
SwapMemory
()
(
SwapMemoryStat
,
error
)
{
ret
:=
Swap
_m
emoryStat
{}
ret
:=
Swap
M
emoryStat
{}
sysinfo
:=
&
syscall
.
Sysinfo_t
{}
if
err
:=
syscall
.
Sysinfo
(
sysinfo
);
err
!=
nil
{
...
...
net.go
浏览文件 @
d511748b
...
...
@@ -13,7 +13,7 @@ type NetIOCountersStat struct {
}
type
Addr
struct
{
I
p
string
`json:"ip""`
I
P
string
`json:"ip""`
Port
uint32
`json:"port""`
}
...
...
net_linux.go
浏览文件 @
d511748b
...
...
@@ -10,27 +10,27 @@ func NetIOCounters() ([]NetIOCountersStat, error) {
filename
:=
"/proc/net/dev"
lines
,
err
:=
ReadLines
(
filename
)
if
err
!=
nil
{
return
make
([]
Net
_io_c
ountersStat
,
0
),
err
return
make
([]
Net
IOC
ountersStat
,
0
),
err
}
statlen
:=
len
(
lines
)
-
1
ret
:=
make
([]
Net
_io_c
ountersStat
,
0
,
statlen
)
ret
:=
make
([]
Net
IOC
ountersStat
,
0
,
statlen
)
for
_
,
line
:=
range
lines
[
2
:
]
{
fields
:=
strings
.
Fields
(
line
)
if
fields
[
0
]
==
""
{
continue
}
nic
:=
Net
_io_c
ountersStat
{
Name
:
strings
.
Trim
(
fields
[
0
],
":"
),
Bytes
_r
ecv
:
parseUint64
(
fields
[
1
]),
Errin
:
parseUint64
(
fields
[
2
]),
Dropin
:
parseUint64
(
fields
[
3
]),
Bytes
_s
ent
:
parseUint64
(
fields
[
9
]),
Packets
_s
ent
:
parseUint64
(
fields
[
10
]),
Errout
:
parseUint64
(
fields
[
11
]),
Dropout
:
parseUint64
(
fields
[
12
]),
nic
:=
Net
IOC
ountersStat
{
Name
:
strings
.
Trim
(
fields
[
0
],
":"
),
Bytes
R
ecv
:
parseUint64
(
fields
[
1
]),
Errin
:
parseUint64
(
fields
[
2
]),
Dropin
:
parseUint64
(
fields
[
3
]),
Bytes
S
ent
:
parseUint64
(
fields
[
9
]),
Packets
S
ent
:
parseUint64
(
fields
[
10
]),
Errout
:
parseUint64
(
fields
[
11
]),
Dropout
:
parseUint64
(
fields
[
12
]),
}
ret
=
append
(
ret
,
nic
)
}
...
...
process.go
浏览文件 @
d511748b
...
...
@@ -20,7 +20,7 @@ type RlimitStat struct {
Hard
int32
`json:"hard"`
}
type
I
o
CountersStat
struct
{
type
I
O
CountersStat
struct
{
ReadCount
int32
`json:"read_count"`
WriteCount
int32
`json:"write_count"`
ReadBytes
int32
`json:"read_bytes"`
...
...
process_freebsd.go
浏览文件 @
d511748b
...
...
@@ -70,7 +70,7 @@ func (p *Process) Terminal() (string, error) {
func
(
p
*
Process
)
Nice
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
I
o
nice
()
(
int32
,
error
)
{
func
(
p
*
Process
)
I
O
nice
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
Rlimit
()
([]
RlimitStat
,
error
)
{
...
...
process_freebsd_amd64.go
浏览文件 @
d511748b
...
...
@@ -13,84 +13,84 @@ const (
)
// copied from sys/user.h
type
Kinfo
_p
roc
struct
{
Ki
_s
tructsize
int32
Ki
_l
ayout
int32
Ki
_a
rgs
int64
Ki
_p
addr
int64
Ki
_a
ddr
int64
Ki
_t
racep
int64
Ki
_t
extvp
int64
Ki
_f
d
int64
Ki
_v
mspace
int64
Ki
_w
chan
int64
Ki
_p
id
int32
Ki
_p
pid
int32
Ki
_p
gid
int32
Ki
_t
pgid
int32
Ki
_s
id
int32
Ki
_t
sid
int32
Ki
_j
obc
[
2
]
byte
Ki
_spare_short1
[
2
]
byte
Ki
_t
dev
int32
Ki
_s
iglist
[
16
]
byte
Ki
_s
igmask
[
16
]
byte
Ki
_s
igignore
[
16
]
byte
Ki
_s
igcatch
[
16
]
byte
Ki
_uid
int32
Ki
_r
uid
int32
Ki
_s
vuid
int32
Ki
_r
gid
int32
Ki
_s
vgid
int32
Ki
_n
groups
[
2
]
byte
Ki
_spare_short2
[
2
]
byte
Ki
_g
roups
[
64
]
byte
Ki
_s
ize
int64
Ki
_r
ssize
int64
Ki
_s
wrss
int64
Ki
_t
size
int64
Ki
_d
size
int64
Ki
_s
size
int64
Ki
_x
stat
[
2
]
byte
Ki
_a
cflag
[
2
]
byte
Ki
_p
ctcpu
int32
Ki
_e
stcpu
int32
Ki
_s
lptime
int32
Ki
_s
wtime
int32
Ki
_c
ow
int32
Ki
_r
untime
int64
Ki
_s
tart
[
16
]
byte
Ki
_c
hildtime
[
16
]
byte
Ki
_f
lag
int64
Ki
_kiflag
int64
Ki
_t
raceflag
int32
Ki
_s
tat
[
1
]
byte
Ki
_n
ice
[
1
]
byte
Ki
_l
ock
[
1
]
byte
Ki
_r
qindex
[
1
]
byte
Ki
_o
ncpu
[
1
]
byte
Ki
_l
astcpu
[
1
]
byte
Ki
_o
comm
[
17
]
byte
Ki
_w
mesg
[
9
]
byte
Ki
_l
ogin
[
18
]
byte
Ki
_l
ockname
[
9
]
byte
Ki
_c
omm
[
20
]
byte
Ki
_e
mul
[
17
]
byte
Ki
_s
parestrings
[
68
]
byte
Ki
_s
pareints
[
36
]
byte
Ki
_cr_flags
int32
Ki
_j
id
int32
Ki
_n
umthreads
int32
Ki
_t
id
int32
Ki
_p
ri
int32
Ki
_r
usage
[
144
]
byte
Ki
_rusage_ch
[
144
]
byte
Ki
_p
cb
int64
Ki
_k
stack
int64
Ki
_u
data
int64
Ki
_t
daddr
int64
Ki
_s
pareptrs
[
48
]
byte
Ki
_s
pareint64s
[
96
]
byte
Ki
_s
flag
int64
Ki
_t
dflags
int64
type
Kinfo
P
roc
struct
{
Ki
S
tructsize
int32
Ki
L
ayout
int32
Ki
A
rgs
int64
Ki
P
addr
int64
Ki
A
ddr
int64
Ki
T
racep
int64
Ki
T
extvp
int64
Ki
F
d
int64
Ki
V
mspace
int64
Ki
W
chan
int64
Ki
P
id
int32
Ki
P
pid
int32
Ki
P
gid
int32
Ki
T
pgid
int32
Ki
S
id
int32
Ki
T
sid
int32
Ki
J
obc
[
2
]
byte
Ki
SpareShort1
[
2
]
byte
Ki
T
dev
int32
Ki
S
iglist
[
16
]
byte
Ki
S
igmask
[
16
]
byte
Ki
S
igignore
[
16
]
byte
Ki
S
igcatch
[
16
]
byte
Ki
UID
int32
Ki
R
uid
int32
Ki
S
vuid
int32
Ki
R
gid
int32
Ki
S
vgid
int32
Ki
N
groups
[
2
]
byte
Ki
SpareShort2
[
2
]
byte
Ki
G
roups
[
64
]
byte
Ki
S
ize
int64
Ki
R
ssize
int64
Ki
S
wrss
int64
Ki
T
size
int64
Ki
D
size
int64
Ki
S
size
int64
Ki
X
stat
[
2
]
byte
Ki
A
cflag
[
2
]
byte
Ki
P
ctcpu
int32
Ki
E
stcpu
int32
Ki
S
lptime
int32
Ki
S
wtime
int32
Ki
C
ow
int32
Ki
R
untime
int64
Ki
S
tart
[
16
]
byte
Ki
C
hildtime
[
16
]
byte
Ki
F
lag
int64
Ki
Kflag
int64
Ki
T
raceflag
int32
Ki
S
tat
[
1
]
byte
Ki
N
ice
[
1
]
byte
Ki
L
ock
[
1
]
byte
Ki
R
qindex
[
1
]
byte
Ki
O
ncpu
[
1
]
byte
Ki
L
astcpu
[
1
]
byte
Ki
O
comm
[
17
]
byte
Ki
W
mesg
[
9
]
byte
Ki
L
ogin
[
18
]
byte
Ki
L
ockname
[
9
]
byte
Ki
C
omm
[
20
]
byte
Ki
E
mul
[
17
]
byte
Ki
S
parestrings
[
68
]
byte
Ki
S
pareints
[
36
]
byte
Ki
CrFlags
int32
Ki
J
id
int32
Ki
N
umthreads
int32
Ki
T
id
int32
Ki
P
ri
int32
Ki
R
usage
[
144
]
byte
Ki
RusageCh
[
144
]
byte
Ki
P
cb
int64
Ki
K
stack
int64
Ki
U
data
int64
Ki
T
daddr
int64
Ki
S
pareptrs
[
48
]
byte
Ki
S
pareint64s
[
96
]
byte
Ki
S
flag
int64
Ki
T
dflags
int64
}
process_linux.go
浏览文件 @
d511748b
...
...
@@ -114,7 +114,7 @@ func (p *Process) Nice() (int32, error) {
}
return
nice
,
nil
}
func
(
p
*
Process
)
I
o
nice
()
(
int32
,
error
)
{
func
(
p
*
Process
)
I
O
nice
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
Rlimit
()
([]
RlimitStat
,
error
)
{
...
...
@@ -179,7 +179,7 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
Connections
()
([]
Net
_c
onnectionStat
,
error
)
{
func
(
p
*
Process
)
Connections
()
([]
Net
C
onnectionStat
,
error
)
{
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
...
...
@@ -258,7 +258,7 @@ func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
**/
// Get num_fds from /proc/(pid)/fd
func
(
p
*
Process
)
fillFromfd
()
(
int32
,
[]
*
Open
_f
ilesStat
,
error
)
{
func
(
p
*
Process
)
fillFromfd
()
(
int32
,
[]
*
Open
F
ilesStat
,
error
)
{
pid
:=
p
.
Pid
statPath
:=
filepath
.
Join
(
"/"
,
"proc"
,
strconv
.
Itoa
(
int
(
pid
)),
"fd"
)
d
,
err
:=
os
.
Open
(
statPath
)
...
...
@@ -276,7 +276,7 @@ func (p *Process) fillFromfd() (int32, []*Open_filesStat, error) {
if
err
!=
nil
{
continue
}
o
:=
&
Open
_f
ilesStat
{
o
:=
&
Open
F
ilesStat
{
Path
:
filepath
,
Fd
:
parseUint64
(
fd
),
}
...
...
@@ -328,7 +328,7 @@ func (p *Process) fillFromCmdline() (string, error) {
}
// Get memory info from /proc/(pid)/statm
func
(
p
*
Process
)
fillFromStatm
()
(
*
Memory
_infoStat
,
*
Memory_info_e
xStat
,
error
)
{
func
(
p
*
Process
)
fillFromStatm
()
(
*
Memory
InfoStat
,
*
MemoryInfoE
xStat
,
error
)
{
pid
:=
p
.
Pid
memPath
:=
filepath
.
Join
(
"/"
,
"proc"
,
strconv
.
Itoa
(
int
(
pid
)),
"statm"
)
contents
,
err
:=
ioutil
.
ReadFile
(
memPath
)
...
...
@@ -421,7 +421,7 @@ func (p *Process) fillFromStat() (string, int32, *CPUTimesStat, int64, int32, er
stime
,
_
:=
strconv
.
ParseFloat
(
fields
[
14
],
64
)
cpuTimes
:=
&
CPUTimesStat
{
C
pu
:
"cpu"
,
C
PU
:
"cpu"
,
User
:
float32
(
utime
*
(
1000
/
CLOCK_TICKS
)),
System
:
float32
(
stime
*
(
1000
/
CLOCK_TICKS
)),
}
...
...
process_posix.go
浏览文件 @
d511748b
...
...
@@ -13,7 +13,7 @@ import (
// POSIX
func
getTerminalMap
()
(
map
[
uint64
]
string
,
error
)
{
ret
:=
make
(
map
[
uint64
]
string
)
termfiles
:=
make
([]
string
,
0
)
var
termfiles
[]
string
d
,
err
:=
os
.
Open
(
"/dev"
)
if
err
!=
nil
{
...
...
@@ -48,20 +48,20 @@ func getTerminalMap() (map[uint64]string, error) {
return
ret
,
nil
}
func
(
p
*
Process
)
Send
_s
ignal
(
sig
syscall
.
Signal
)
error
{
sig
_as_s
tr
:=
"INT"
func
(
p
*
Process
)
Send
S
ignal
(
sig
syscall
.
Signal
)
error
{
sig
AsS
tr
:=
"INT"
switch
sig
{
case
syscall
.
SIGSTOP
:
sig
_as_s
tr
=
"STOP"
sig
AsS
tr
=
"STOP"
case
syscall
.
SIGCONT
:
sig
_as_s
tr
=
"CONT"
sig
AsS
tr
=
"CONT"
case
syscall
.
SIGTERM
:
sig
_as_s
tr
=
"TERM"
sig
AsS
tr
=
"TERM"
case
syscall
.
SIGKILL
:
sig
_as_s
tr
=
"KILL"
sig
AsS
tr
=
"KILL"
}
cmd
:=
exec
.
Command
(
"kill"
,
"-s"
,
sig
_as_s
tr
,
strconv
.
Itoa
(
int
(
p
.
Pid
)))
cmd
:=
exec
.
Command
(
"kill"
,
"-s"
,
sig
AsS
tr
,
strconv
.
Itoa
(
int
(
p
.
Pid
)))
cmd
.
Stderr
=
os
.
Stderr
err
:=
cmd
.
Run
()
if
err
!=
nil
{
...
...
@@ -72,14 +72,14 @@ func (p *Process) Send_signal(sig syscall.Signal) error {
}
func
(
p
*
Process
)
Suspend
()
error
{
return
p
.
Send
_s
ignal
(
syscall
.
SIGSTOP
)
return
p
.
Send
S
ignal
(
syscall
.
SIGSTOP
)
}
func
(
p
*
Process
)
Resume
()
error
{
return
p
.
Send
_s
ignal
(
syscall
.
SIGCONT
)
return
p
.
Send
S
ignal
(
syscall
.
SIGCONT
)
}
func
(
p
*
Process
)
Terminate
()
error
{
return
p
.
Send
_s
ignal
(
syscall
.
SIGTERM
)
return
p
.
Send
S
ignal
(
syscall
.
SIGTERM
)
}
func
(
p
*
Process
)
Kill
()
error
{
return
p
.
Send
_s
ignal
(
syscall
.
SIGKILL
)
return
p
.
Send
S
ignal
(
syscall
.
SIGKILL
)
}
process_test.go
浏览文件 @
d511748b
...
...
@@ -19,12 +19,12 @@ func Test_Pids(t *testing.T) {
}
func
Test_Pid_exists
(
t
*
testing
.
T
)
{
check
_p
id
:=
1
check
P
id
:=
1
if
runtime
.
GOOS
==
"windows"
{
check
_p
id
=
0
check
P
id
=
0
}
ret
,
err
:=
PidExists
(
int32
(
check
_p
id
))
ret
,
err
:=
PidExists
(
int32
(
check
P
id
))
if
err
!=
nil
{
t
.
Errorf
(
"error %v"
,
err
)
}
...
...
@@ -35,12 +35,12 @@ func Test_Pid_exists(t *testing.T) {
}
func
Test_NewProcess
(
t
*
testing
.
T
)
{
check
_p
id
:=
1
check
P
id
:=
1
if
runtime
.
GOOS
==
"windows"
{
check
_p
id
=
0
check
P
id
=
0
}
ret
,
err
:=
NewProcess
(
int32
(
check
_p
id
))
ret
,
err
:=
NewProcess
(
int32
(
check
P
id
))
if
err
!=
nil
{
t
.
Errorf
(
"error %v"
,
err
)
}
...
...
@@ -50,12 +50,12 @@ func Test_NewProcess(t *testing.T) {
}
func
Test_Process_memory_maps
(
t
*
testing
.
T
)
{
check
_p
id
:=
os
.
Getpid
()
check
P
id
:=
os
.
Getpid
()
if
runtime
.
GOOS
==
"windows"
{
check
_p
id
=
0
check
P
id
=
0
}
return
ret
,
err
:=
NewProcess
(
int32
(
check
_p
id
))
ret
,
err
:=
NewProcess
(
int32
(
check
P
id
))
mmaps
,
err
:=
ret
.
MemoryMaps
(
false
)
if
err
!=
nil
{
...
...
@@ -68,11 +68,11 @@ func Test_Process_memory_maps(t *testing.T) {
}
func
Test_Process_Ppid
(
t
*
testing
.
T
)
{
check
_p
id
:=
os
.
Getpid
()
check
P
id
:=
os
.
Getpid
()
if
runtime
.
GOOS
==
"windows"
{
check
_p
id
=
7960
check
P
id
=
7960
}
ret
,
err
:=
NewProcess
(
int32
(
check
_p
id
))
ret
,
err
:=
NewProcess
(
int32
(
check
P
id
))
v
,
err
:=
ret
.
Ppid
()
if
err
!=
nil
{
...
...
process_test_posix.go
浏览文件 @
d511748b
...
...
@@ -8,11 +8,11 @@ import (
"testing"
)
func
Test
_
SendSignal
(
t
*
testing
.
T
)
{
check
_p
id
:=
os
.
Getpid
()
func
TestSendSignal
(
t
*
testing
.
T
)
{
check
P
id
:=
os
.
Getpid
()
p
,
_
:=
NewProcess
(
int32
(
check
_p
id
))
err
:=
p
.
Send
_s
ignal
(
syscall
.
SIGCONT
)
p
,
_
:=
NewProcess
(
int32
(
check
P
id
))
err
:=
p
.
Send
S
ignal
(
syscall
.
SIGCONT
)
if
err
!=
nil
{
t
.
Errorf
(
"send signal %v"
,
err
)
}
...
...
process_windows.go
浏览文件 @
d511748b
...
...
@@ -99,7 +99,7 @@ func (p *Process) Terminal() (string, error) {
func
(
p
*
Process
)
Nice
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
I
o
nice
()
(
int32
,
error
)
{
func
(
p
*
Process
)
I
O
nice
()
(
int32
,
error
)
{
return
0
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
Rlimit
()
([]
RlimitStat
,
error
)
{
...
...
@@ -107,7 +107,7 @@ func (p *Process) Rlimit() ([]RlimitStat, error) {
return
rlimit
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
I
oCounters
()
(
*
Io
CountersStat
,
error
)
{
func
(
p
*
Process
)
I
OCounters
()
(
*
IO
CountersStat
,
error
)
{
return
nil
,
errors
.
New
(
"not implemented yet"
)
}
func
(
p
*
Process
)
NumCtxSwitches
()
(
int32
,
error
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录