Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
a1c1d7b2
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,发现更多精彩内容 >>
提交
a1c1d7b2
编写于
11月 27, 2014
作者:
S
Shirou WAKAYAMA
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix on Linux.
上级
d11680c7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
38 addition
and
36 deletion
+38
-36
common/common.go
common/common.go
+2
-2
docker/docker_linux.go
docker/docker_linux.go
+4
-3
host/host_linux.go
host/host_linux.go
+30
-30
process/process_linux.go
process/process_linux.go
+2
-1
未找到文件。
common/common.go
浏览文件 @
a1c1d7b2
...
...
@@ -94,7 +94,7 @@ func mustParseFloat64(val string) float64 {
}
// Check the target string slice containes src or not
func
s
tringContains
(
target
[]
string
,
src
string
)
bool
{
func
S
tringContains
(
target
[]
string
,
src
string
)
bool
{
for
_
,
t
:=
range
target
{
if
t
==
src
{
return
true
...
...
@@ -126,7 +126,7 @@ func attributes(m interface{}) map[string]reflect.Type {
return
attrs
}
func
p
athExists
(
filename
string
)
bool
{
func
P
athExists
(
filename
string
)
bool
{
if
_
,
err
:=
os
.
Stat
(
filename
);
err
==
nil
{
return
true
}
...
...
docker/docker_linux.go
浏览文件 @
a1c1d7b2
...
...
@@ -10,6 +10,7 @@ import (
"strings"
common
"github.com/shirou/gopsutil/common"
cpu
"github.com/shirou/gopsutil/cpu"
)
type
CgroupMemStat
struct
{
...
...
@@ -64,7 +65,7 @@ func GetDockerIDList() ([]string, error) {
// containerid is same as docker id if you use docker.
// If you use container via systemd.slice, you could use
// containerid = docker-<container id>.scope and base=/sys/fs/cgroup/cpuacct/system.slice/
func
CgroupCPU
(
containerid
string
,
base
string
)
(
*
CPUTimesStat
,
error
)
{
func
CgroupCPU
(
containerid
string
,
base
string
)
(
*
cpu
.
CPUTimesStat
,
error
)
{
if
len
(
base
)
==
0
{
base
=
"/sys/fs/cgroup/cpuacct/docker"
}
...
...
@@ -75,7 +76,7 @@ func CgroupCPU(containerid string, base string) (*CPUTimesStat, error) {
if
len
(
containerid
)
==
0
{
containerid
=
"all"
}
ret
:=
&
CPUTimesStat
{
CPU
:
containerid
}
ret
:=
&
cpu
.
CPUTimesStat
{
CPU
:
containerid
}
for
_
,
line
:=
range
lines
{
fields
:=
strings
.
Split
(
line
,
" "
)
if
fields
[
0
]
==
"user"
{
...
...
@@ -95,7 +96,7 @@ func CgroupCPU(containerid string, base string) (*CPUTimesStat, error) {
return
ret
,
nil
}
func
CgroupCPUDocker
(
containerid
string
)
(
*
CPUTimesStat
,
error
)
{
func
CgroupCPUDocker
(
containerid
string
)
(
*
cpu
.
CPUTimesStat
,
error
)
{
return
CgroupCPU
(
containerid
,
"/sys/fs/cgroup/cpuacct/docker"
)
}
...
...
host/host_linux.go
浏览文件 @
a1c1d7b2
...
...
@@ -105,7 +105,7 @@ func Users() ([]UserStat, error) {
func
getLSB
()
(
*
LSB
,
error
)
{
ret
:=
&
LSB
{}
if
p
athExists
(
"/etc/lsb-release"
)
{
if
common
.
P
athExists
(
"/etc/lsb-release"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/etc/lsb-release"
)
if
err
!=
nil
{
return
ret
,
err
// return empty
...
...
@@ -126,7 +126,7 @@ func getLSB() (*LSB, error) {
ret
.
Description
=
field
[
1
]
}
}
}
else
if
p
athExists
(
"/usr/bin/lsb_release"
)
{
}
else
if
common
.
P
athExists
(
"/usr/bin/lsb_release"
)
{
out
,
err
:=
exec
.
Command
(
"/usr/bin/lsb_release"
)
.
Output
()
if
err
!=
nil
{
return
ret
,
err
...
...
@@ -160,19 +160,19 @@ func GetPlatformInformation() (platform string, family string, version string, e
lsb
=
&
LSB
{}
}
if
p
athExists
(
"/etc/oracle-release"
)
{
if
common
.
P
athExists
(
"/etc/oracle-release"
)
{
platform
=
"oracle"
contents
,
err
:=
common
.
ReadLines
(
"/etc/oracle-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
}
}
else
if
p
athExists
(
"/etc/enterprise-release"
)
{
}
else
if
common
.
P
athExists
(
"/etc/enterprise-release"
)
{
platform
=
"oracle"
contents
,
err
:=
common
.
ReadLines
(
"/etc/enterprise-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
}
}
else
if
p
athExists
(
"/etc/debian_version"
)
{
}
else
if
common
.
P
athExists
(
"/etc/debian_version"
)
{
if
lsb
.
ID
==
"Ubuntu"
{
platform
=
"ubuntu"
version
=
lsb
.
Release
...
...
@@ -180,7 +180,7 @@ func GetPlatformInformation() (platform string, family string, version string, e
platform
=
"linuxmint"
version
=
lsb
.
Release
}
else
{
if
p
athExists
(
"/usr/bin/raspi-config"
)
{
if
common
.
P
athExists
(
"/usr/bin/raspi-config"
)
{
platform
=
"raspbian"
}
else
{
platform
=
"debian"
...
...
@@ -190,19 +190,19 @@ func GetPlatformInformation() (platform string, family string, version string, e
version
=
contents
[
0
]
}
}
}
else
if
p
athExists
(
"/etc/redhat-release"
)
{
}
else
if
common
.
P
athExists
(
"/etc/redhat-release"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/etc/redhat-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
platform
=
getRedhatishPlatform
(
contents
)
}
}
else
if
p
athExists
(
"/etc/system-release"
)
{
}
else
if
common
.
P
athExists
(
"/etc/system-release"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/etc/system-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
platform
=
getRedhatishPlatform
(
contents
)
}
}
else
if
p
athExists
(
"/etc/gentoo-release"
)
{
}
else
if
common
.
P
athExists
(
"/etc/gentoo-release"
)
{
platform
=
"gentoo"
contents
,
err
:=
common
.
ReadLines
(
"/etc/gentoo-release"
)
if
err
==
nil
{
...
...
@@ -210,7 +210,7 @@ func GetPlatformInformation() (platform string, family string, version string, e
}
// TODO: suse detection
// TODO: slackware detecion
}
else
if
p
athExists
(
"/etc/arch-release"
)
{
}
else
if
common
.
P
athExists
(
"/etc/arch-release"
)
{
platform
=
"arch"
// TODO: exherbo detection
}
else
if
lsb
.
ID
==
"RedHat"
{
...
...
@@ -280,78 +280,78 @@ func GetVirtualization() (string, string, error) {
var
system
string
var
role
string
if
p
athExists
(
"/proc/xen"
)
{
if
common
.
P
athExists
(
"/proc/xen"
)
{
system
=
"xen"
role
=
"guest"
// assume guest
if
p
athExists
(
"/proc/xen/capabilities"
)
{
if
common
.
P
athExists
(
"/proc/xen/capabilities"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/xen/capabilities"
)
if
err
==
nil
{
if
s
tringContains
(
contents
,
"control_d"
)
{
if
common
.
S
tringContains
(
contents
,
"control_d"
)
{
role
=
"host"
}
}
}
}
if
p
athExists
(
"/proc/modules"
)
{
if
common
.
P
athExists
(
"/proc/modules"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/modules"
)
if
err
==
nil
{
if
s
tringContains
(
contents
,
"kvm"
)
{
if
common
.
S
tringContains
(
contents
,
"kvm"
)
{
system
=
"kvm"
role
=
"host"
}
else
if
s
tringContains
(
contents
,
"vboxdrv"
)
{
}
else
if
common
.
S
tringContains
(
contents
,
"vboxdrv"
)
{
system
=
"vbox"
role
=
"host"
}
else
if
s
tringContains
(
contents
,
"vboxguest"
)
{
}
else
if
common
.
S
tringContains
(
contents
,
"vboxguest"
)
{
system
=
"vbox"
role
=
"guest"
}
}
}
if
p
athExists
(
"/proc/cpuinfo"
)
{
if
common
.
P
athExists
(
"/proc/cpuinfo"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/cpuinfo"
)
if
err
==
nil
{
if
s
tringContains
(
contents
,
"QEMU Virtual CPU"
)
||
s
tringContains
(
contents
,
"Common KVM processor"
)
||
s
tringContains
(
contents
,
"Common 32-bit KVM processor"
)
{
if
common
.
S
tringContains
(
contents
,
"QEMU Virtual CPU"
)
||
common
.
S
tringContains
(
contents
,
"Common KVM processor"
)
||
common
.
S
tringContains
(
contents
,
"Common 32-bit KVM processor"
)
{
system
=
"kvm"
role
=
"guest"
}
}
}
if
p
athExists
(
"/proc/bc/0"
)
{
if
common
.
P
athExists
(
"/proc/bc/0"
)
{
system
=
"openvz"
role
=
"host"
}
else
if
p
athExists
(
"/proc/vz"
)
{
}
else
if
common
.
P
athExists
(
"/proc/vz"
)
{
system
=
"openvz"
role
=
"guest"
}
// not use dmidecode because it requires root
if
p
athExists
(
"/proc/self/status"
)
{
if
common
.
P
athExists
(
"/proc/self/status"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/self/status"
)
if
err
==
nil
{
if
s
tringContains
(
contents
,
"s_context:"
)
||
s
tringContains
(
contents
,
"VxID:"
)
{
if
common
.
S
tringContains
(
contents
,
"s_context:"
)
||
common
.
S
tringContains
(
contents
,
"VxID:"
)
{
system
=
"linux-vserver"
}
// TODO: guest or host
}
}
if
p
athExists
(
"/proc/self/cgroup"
)
{
if
common
.
P
athExists
(
"/proc/self/cgroup"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/self/cgroup"
)
if
err
==
nil
{
if
s
tringContains
(
contents
,
"lxc"
)
||
s
tringContains
(
contents
,
"docker"
)
{
if
common
.
S
tringContains
(
contents
,
"lxc"
)
||
common
.
S
tringContains
(
contents
,
"docker"
)
{
system
=
"lxc"
role
=
"guest"
}
else
if
p
athExists
(
"/usr/bin/lxc-version"
)
{
// TODO: which
}
else
if
common
.
P
athExists
(
"/usr/bin/lxc-version"
)
{
// TODO: which
system
=
"lxc"
role
=
"host"
}
...
...
process/process_linux.go
浏览文件 @
a1c1d7b2
...
...
@@ -13,6 +13,7 @@ import (
common
"github.com/shirou/gopsutil/common"
cpu
"github.com/shirou/gopsutil/cpu"
host
"github.com/shirou/gopsutil/host"
net
"github.com/shirou/gopsutil/net"
)
...
...
@@ -555,7 +556,7 @@ func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32
System
:
float32
(
stime
*
(
1000
/
ClockTicks
)),
}
bootTime
,
_
:=
BootTime
()
bootTime
,
_
:=
host
.
BootTime
()
t
,
err
:=
strconv
.
ParseUint
(
fields
[
21
],
10
,
64
)
if
err
!=
nil
{
return
""
,
0
,
nil
,
0
,
0
,
err
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录