Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
d11680c7
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,发现更多精彩内容 >>
提交
d11680c7
编写于
11月 27, 2014
作者:
W
WAKAYAMA shirou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs on FreeBSD.
上级
a4671fcc
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
40 addition
and
30 deletion
+40
-30
common/common.go
common/common.go
+6
-6
cpu/cpu_freebsd.go
cpu/cpu_freebsd.go
+1
-1
cpu/cpu_linux.go
cpu/cpu_linux.go
+5
-3
disk/disk_freebsd.go
disk/disk_freebsd.go
+1
-1
disk/disk_linux.go
disk/disk_linux.go
+4
-2
docker/docker_linux.go
docker/docker_linux.go
+4
-2
host/host_linux.go
host/host_linux.go
+12
-12
mem/mem_linux.go
mem/mem_linux.go
+4
-2
net/net_linux.go
net/net_linux.go
+3
-1
未找到文件。
common/common.go
浏览文件 @
d11680c7
...
...
@@ -17,18 +17,18 @@ import (
var
NotImplementedError
=
errors
.
New
(
"not implemented yet"
)
//
r
eadLines reads contents from file and splits them by new line.
// A convenience wrapper to
r
eadLinesOffsetN(filename, 0, -1).
func
r
eadLines
(
filename
string
)
([]
string
,
error
)
{
return
r
eadLinesOffsetN
(
filename
,
0
,
-
1
)
//
R
eadLines reads contents from file and splits them by new line.
// A convenience wrapper to
R
eadLinesOffsetN(filename, 0, -1).
func
R
eadLines
(
filename
string
)
([]
string
,
error
)
{
return
R
eadLinesOffsetN
(
filename
,
0
,
-
1
)
}
//
r
eadLines reads contents from file and splits them by new line.
//
R
eadLines reads contents from file and splits them by new line.
// The offset tells at which line number to start.
// The count determines the number of lines to read (starting from offset):
// n >= 0: at most n lines
// n < 0: whole file
func
r
eadLinesOffsetN
(
filename
string
,
offset
uint
,
n
int
)
([]
string
,
error
)
{
func
R
eadLinesOffsetN
(
filename
string
,
offset
uint
,
n
int
)
([]
string
,
error
)
{
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
return
[]
string
{
""
},
err
...
...
cpu/cpu_freebsd.go
浏览文件 @
d11680c7
...
...
@@ -89,7 +89,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
// Returns only one CPUInfoStat on FreeBSD
func
CPUInfo
()
([]
CPUInfoStat
,
error
)
{
filename
:=
"/var/run/dmesg.boot"
lines
,
_
:=
r
eadLines
(
filename
)
lines
,
_
:=
common
.
R
eadLines
(
filename
)
var
ret
[]
CPUInfoStat
...
...
cpu/cpu_linux.go
浏览文件 @
d11680c7
...
...
@@ -6,6 +6,8 @@ import (
"errors"
"strconv"
"strings"
common
"github.com/shirou/gopsutil/common"
)
func
CPUTimes
(
percpu
bool
)
([]
CPUTimesStat
,
error
)
{
...
...
@@ -13,9 +15,9 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
var
lines
[]
string
if
percpu
{
ncpu
,
_
:=
CPUCounts
(
true
)
lines
,
_
=
r
eadLinesOffsetN
(
filename
,
1
,
ncpu
)
lines
,
_
=
common
.
R
eadLinesOffsetN
(
filename
,
1
,
ncpu
)
}
else
{
lines
,
_
=
r
eadLinesOffsetN
(
filename
,
0
,
1
)
lines
,
_
=
common
.
R
eadLinesOffsetN
(
filename
,
0
,
1
)
}
ret
:=
make
([]
CPUTimesStat
,
0
,
len
(
lines
))
...
...
@@ -33,7 +35,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
func
CPUInfo
()
([]
CPUInfoStat
,
error
)
{
filename
:=
"/proc/cpuinfo"
lines
,
_
:=
r
eadLines
(
filename
)
lines
,
_
:=
common
.
R
eadLines
(
filename
)
var
ret
[]
CPUInfoStat
...
...
disk/disk_freebsd.go
浏览文件 @
d11680c7
...
...
@@ -101,7 +101,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret
:=
make
(
map
[
string
]
DiskIOCountersStat
,
0
)
for
_
,
stat
:=
range
fs
{
name
:=
ByteToString
(
stat
.
FMntonname
[
:
])
name
:=
common
.
ByteToString
(
stat
.
FMntonname
[
:
])
d
:=
DiskIOCountersStat
{
Name
:
name
,
ReadCount
:
stat
.
FSyncwrites
+
stat
.
FAsyncwrites
,
...
...
disk/disk_linux.go
浏览文件 @
d11680c7
...
...
@@ -7,6 +7,8 @@ import (
"os/exec"
"strconv"
"strings"
common
"github.com/shirou/gopsutil/common"
)
const
(
...
...
@@ -18,7 +20,7 @@ const (
func
DiskPartitions
(
all
bool
)
([]
DiskPartitionStat
,
error
)
{
filename
:=
"/etc/mtab"
lines
,
err
:=
r
eadLines
(
filename
)
lines
,
err
:=
common
.
R
eadLines
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -41,7 +43,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
func
DiskIOCounters
()
(
map
[
string
]
DiskIOCountersStat
,
error
)
{
filename
:=
"/proc/diskstats"
lines
,
err
:=
r
eadLines
(
filename
)
lines
,
err
:=
common
.
R
eadLines
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
docker/docker_linux.go
浏览文件 @
d11680c7
...
...
@@ -8,6 +8,8 @@ import (
"path"
"strconv"
"strings"
common
"github.com/shirou/gopsutil/common"
)
type
CgroupMemStat
struct
{
...
...
@@ -68,7 +70,7 @@ func CgroupCPU(containerid string, base string) (*CPUTimesStat, error) {
}
path
:=
path
.
Join
(
base
,
containerid
,
"cpuacct.stat"
)
lines
,
_
:=
r
eadLines
(
path
)
lines
,
_
:=
common
.
R
eadLines
(
path
)
// empty containerid means all cgroup
if
len
(
containerid
)
==
0
{
containerid
=
"all"
...
...
@@ -106,7 +108,7 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) {
if
len
(
containerid
)
==
0
{
containerid
=
"all"
}
lines
,
_
:=
r
eadLines
(
path
)
lines
,
_
:=
common
.
R
eadLines
(
path
)
ret
:=
&
CgroupMemStat
{
ContainerID
:
containerid
}
for
_
,
line
:=
range
lines
{
fields
:=
strings
.
Split
(
line
,
" "
)
...
...
host/host_linux.go
浏览文件 @
d11680c7
...
...
@@ -106,7 +106,7 @@ func Users() ([]UserStat, error) {
func
getLSB
()
(
*
LSB
,
error
)
{
ret
:=
&
LSB
{}
if
pathExists
(
"/etc/lsb-release"
)
{
contents
,
err
:=
r
eadLines
(
"/etc/lsb-release"
)
contents
,
err
:=
common
.
R
eadLines
(
"/etc/lsb-release"
)
if
err
!=
nil
{
return
ret
,
err
// return empty
}
...
...
@@ -162,13 +162,13 @@ func GetPlatformInformation() (platform string, family string, version string, e
if
pathExists
(
"/etc/oracle-release"
)
{
platform
=
"oracle"
contents
,
err
:=
r
eadLines
(
"/etc/oracle-release"
)
contents
,
err
:=
common
.
R
eadLines
(
"/etc/oracle-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
}
}
else
if
pathExists
(
"/etc/enterprise-release"
)
{
platform
=
"oracle"
contents
,
err
:=
r
eadLines
(
"/etc/enterprise-release"
)
contents
,
err
:=
common
.
R
eadLines
(
"/etc/enterprise-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
}
...
...
@@ -185,26 +185,26 @@ func GetPlatformInformation() (platform string, family string, version string, e
}
else
{
platform
=
"debian"
}
contents
,
err
:=
r
eadLines
(
"/etc/debian_version"
)
contents
,
err
:=
common
.
R
eadLines
(
"/etc/debian_version"
)
if
err
==
nil
{
version
=
contents
[
0
]
}
}
}
else
if
pathExists
(
"/etc/redhat-release"
)
{
contents
,
err
:=
r
eadLines
(
"/etc/redhat-release"
)
contents
,
err
:=
common
.
R
eadLines
(
"/etc/redhat-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
platform
=
getRedhatishPlatform
(
contents
)
}
}
else
if
pathExists
(
"/etc/system-release"
)
{
contents
,
err
:=
r
eadLines
(
"/etc/system-release"
)
contents
,
err
:=
common
.
R
eadLines
(
"/etc/system-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
platform
=
getRedhatishPlatform
(
contents
)
}
}
else
if
pathExists
(
"/etc/gentoo-release"
)
{
platform
=
"gentoo"
contents
,
err
:=
r
eadLines
(
"/etc/gentoo-release"
)
contents
,
err
:=
common
.
R
eadLines
(
"/etc/gentoo-release"
)
if
err
==
nil
{
version
=
getRedhatishVersion
(
contents
)
}
...
...
@@ -285,7 +285,7 @@ func GetVirtualization() (string, string, error) {
role
=
"guest"
// assume guest
if
pathExists
(
"/proc/xen/capabilities"
)
{
contents
,
err
:=
r
eadLines
(
"/proc/xen/capabilities"
)
contents
,
err
:=
common
.
R
eadLines
(
"/proc/xen/capabilities"
)
if
err
==
nil
{
if
stringContains
(
contents
,
"control_d"
)
{
role
=
"host"
...
...
@@ -294,7 +294,7 @@ func GetVirtualization() (string, string, error) {
}
}
if
pathExists
(
"/proc/modules"
)
{
contents
,
err
:=
r
eadLines
(
"/proc/modules"
)
contents
,
err
:=
common
.
R
eadLines
(
"/proc/modules"
)
if
err
==
nil
{
if
stringContains
(
contents
,
"kvm"
)
{
system
=
"kvm"
...
...
@@ -310,7 +310,7 @@ func GetVirtualization() (string, string, error) {
}
if
pathExists
(
"/proc/cpuinfo"
)
{
contents
,
err
:=
r
eadLines
(
"/proc/cpuinfo"
)
contents
,
err
:=
common
.
R
eadLines
(
"/proc/cpuinfo"
)
if
err
==
nil
{
if
stringContains
(
contents
,
"QEMU Virtual CPU"
)
||
stringContains
(
contents
,
"Common KVM processor"
)
||
...
...
@@ -332,7 +332,7 @@ func GetVirtualization() (string, string, error) {
// not use dmidecode because it requires root
if
pathExists
(
"/proc/self/status"
)
{
contents
,
err
:=
r
eadLines
(
"/proc/self/status"
)
contents
,
err
:=
common
.
R
eadLines
(
"/proc/self/status"
)
if
err
==
nil
{
if
stringContains
(
contents
,
"s_context:"
)
||
...
...
@@ -344,7 +344,7 @@ func GetVirtualization() (string, string, error) {
}
if
pathExists
(
"/proc/self/cgroup"
)
{
contents
,
err
:=
r
eadLines
(
"/proc/self/cgroup"
)
contents
,
err
:=
common
.
R
eadLines
(
"/proc/self/cgroup"
)
if
err
==
nil
{
if
stringContains
(
contents
,
"lxc"
)
||
...
...
mem/mem_linux.go
浏览文件 @
d11680c7
...
...
@@ -6,11 +6,13 @@ import (
"strconv"
"strings"
"syscall"
common
"github.com/shirou/gopsutil/common"
)
func
VirtualMemory
()
(
*
VirtualMemoryStat
,
error
)
{
filename
:=
"/proc/meminfo"
lines
,
_
:=
r
eadLines
(
filename
)
lines
,
_
:=
common
.
R
eadLines
(
filename
)
ret
:=
&
VirtualMemoryStat
{}
for
_
,
line
:=
range
lines
{
...
...
@@ -65,7 +67,7 @@ func SwapMemory() (*SwapMemoryStat, error) {
}
else
{
ret
.
UsedPercent
=
0
}
lines
,
_
:=
r
eadLines
(
"/proc/vmstat"
)
lines
,
_
:=
common
.
R
eadLines
(
"/proc/vmstat"
)
for
_
,
l
:=
range
lines
{
fields
:=
strings
.
Fields
(
l
)
if
len
(
fields
)
<
2
{
...
...
net/net_linux.go
浏览文件 @
d11680c7
...
...
@@ -5,11 +5,13 @@ package gopsutil
import
(
"strconv"
"strings"
common
"github.com/shirou/gopsutil/common"
)
func
NetIOCounters
(
pernic
bool
)
([]
NetIOCountersStat
,
error
)
{
filename
:=
"/proc/net/dev"
lines
,
err
:=
r
eadLines
(
filename
)
lines
,
err
:=
common
.
R
eadLines
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录