Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
b5ffc220
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,体验更适合开发者的 AI 搜索 >>
提交
b5ffc220
编写于
7月 21, 2015
作者:
S
Shirou WAKAYAMA
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
common: Rename StringContains to StringsContains and add StringsHas.
上级
9822959f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
28 addition
and
19 deletion
+28
-19
common/common.go
common/common.go
+12
-2
common/common_test.go
common/common_test.go
+2
-2
disk/disk_test.go
disk/disk_test.go
+1
-1
host/host_linux.go
host/host_linux.go
+11
-12
net/net_darwin.go
net/net_darwin.go
+1
-1
net/net_freebsd.go
net/net_freebsd.go
+1
-1
未找到文件。
common/common.go
浏览文件 @
b5ffc220
...
...
@@ -110,8 +110,8 @@ func mustParseFloat64(val string) float64 {
return
vv
}
//
Check
the target string slice containes src or not
func
String
Contain
s
(
target
[]
string
,
src
string
)
bool
{
//
StringsHas checks
the target string slice containes src or not
func
String
sHa
s
(
target
[]
string
,
src
string
)
bool
{
for
_
,
t
:=
range
target
{
if
strings
.
TrimSpace
(
t
)
==
src
{
return
true
...
...
@@ -120,6 +120,16 @@ func StringContains(target []string, src string) bool {
return
false
}
// StringsContains checks the src in any string of the target string slice
func
StringsContains
(
target
[]
string
,
src
string
)
bool
{
for
_
,
t
:=
range
target
{
if
strings
.
Contains
(
t
,
src
)
{
return
true
}
}
return
false
}
// get struct attributes.
// This method is used only for debugging platform dependent code.
func
attributes
(
m
interface
{})
map
[
string
]
reflect
.
Type
{
...
...
common/common_test.go
浏览文件 @
b5ffc220
...
...
@@ -70,12 +70,12 @@ func TestmustParseFloat64(t *testing.T) {
t
.
Error
(
"could not parse"
)
}
}
func
TestStringContains
(
t
*
testing
.
T
)
{
func
TestString
s
Contains
(
t
*
testing
.
T
)
{
target
,
err
:=
ReadLines
(
"common_test.go"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
!
String
Contains
(
target
,
"func TestString
Contains(t *testing.T) {"
)
{
if
!
String
sContains
(
target
,
"func TestStrings
Contains(t *testing.T) {"
)
{
t
.
Error
(
"cloud not test correctly"
)
}
}
...
...
disk/disk_test.go
浏览文件 @
b5ffc220
...
...
@@ -39,7 +39,7 @@ func TestDisk_io_counters(t *testing.T) {
t
.
Errorf
(
"error %v"
,
err
)
}
if
len
(
ret
)
==
0
{
t
.
Errorf
(
"ret is empty"
,
ret
)
t
.
Errorf
(
"ret is empty
, %v
"
,
ret
)
}
empty
:=
DiskIOCountersStat
{}
for
part
,
io
:=
range
ret
{
...
...
host/host_linux.go
浏览文件 @
b5ffc220
...
...
@@ -328,7 +328,7 @@ func GetVirtualization() (string, string, error) {
if
common
.
PathExists
(
"/proc/xen/capabilities"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/xen/capabilities"
)
if
err
==
nil
{
if
common
.
StringContains
(
contents
,
"control_d"
)
{
if
common
.
String
s
Contains
(
contents
,
"control_d"
)
{
role
=
"host"
}
}
...
...
@@ -337,13 +337,13 @@ func GetVirtualization() (string, string, error) {
if
common
.
PathExists
(
"/proc/modules"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/modules"
)
if
err
==
nil
{
if
common
.
StringContains
(
contents
,
"kvm"
)
{
if
common
.
String
s
Contains
(
contents
,
"kvm"
)
{
system
=
"kvm"
role
=
"host"
}
else
if
common
.
StringContains
(
contents
,
"vboxdrv"
)
{
}
else
if
common
.
String
s
Contains
(
contents
,
"vboxdrv"
)
{
system
=
"vbox"
role
=
"host"
}
else
if
common
.
StringContains
(
contents
,
"vboxguest"
)
{
}
else
if
common
.
String
s
Contains
(
contents
,
"vboxguest"
)
{
system
=
"vbox"
role
=
"guest"
}
...
...
@@ -353,9 +353,9 @@ func GetVirtualization() (string, string, error) {
if
common
.
PathExists
(
"/proc/cpuinfo"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/cpuinfo"
)
if
err
==
nil
{
if
common
.
StringContains
(
contents
,
"QEMU Virtual CPU"
)
||
common
.
StringContains
(
contents
,
"Common KVM processor"
)
||
common
.
StringContains
(
contents
,
"Common 32-bit KVM processor"
)
{
if
common
.
String
s
Contains
(
contents
,
"QEMU Virtual CPU"
)
||
common
.
String
s
Contains
(
contents
,
"Common KVM processor"
)
||
common
.
String
s
Contains
(
contents
,
"Common 32-bit KVM processor"
)
{
system
=
"kvm"
role
=
"guest"
}
...
...
@@ -376,8 +376,8 @@ func GetVirtualization() (string, string, error) {
contents
,
err
:=
common
.
ReadLines
(
"/proc/self/status"
)
if
err
==
nil
{
if
common
.
StringContains
(
contents
,
"s_context:"
)
||
common
.
StringContains
(
contents
,
"VxID:"
)
{
if
common
.
String
s
Contains
(
contents
,
"s_context:"
)
||
common
.
String
s
Contains
(
contents
,
"VxID:"
)
{
system
=
"linux-vserver"
}
// TODO: guest or host
...
...
@@ -387,9 +387,8 @@ func GetVirtualization() (string, string, error) {
if
common
.
PathExists
(
"/proc/self/cgroup"
)
{
contents
,
err
:=
common
.
ReadLines
(
"/proc/self/cgroup"
)
if
err
==
nil
{
if
common
.
StringContains
(
contents
,
"lxc"
)
||
common
.
StringContains
(
contents
,
"docker"
)
{
if
common
.
StringsContains
(
contents
,
"lxc"
)
||
common
.
StringsContains
(
contents
,
"docker"
)
{
system
=
"lxc"
role
=
"guest"
}
else
if
common
.
PathExists
(
"/usr/bin/lxc-version"
)
{
// TODO: which
...
...
net/net_darwin.go
浏览文件 @
b5ffc220
...
...
@@ -26,7 +26,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
// skip first line
continue
}
if
common
.
String
Contain
s
(
exists
,
values
[
0
])
{
if
common
.
String
sHa
s
(
exists
,
values
[
0
])
{
// skip if already get
continue
}
...
...
net/net_freebsd.go
浏览文件 @
b5ffc220
...
...
@@ -25,7 +25,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
if
len
(
values
)
<
1
||
values
[
0
]
==
"Name"
{
continue
}
if
common
.
String
Contain
s
(
exists
,
values
[
0
])
{
if
common
.
String
sHa
s
(
exists
,
values
[
0
])
{
// skip if already get
continue
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录