Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
5f8b99aa
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,发现更多精彩内容 >>
提交
5f8b99aa
编写于
3月 20, 2015
作者:
W
WAKAYAMA Shirou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
windows: GetWmic returns [][]string where string split by ","
上级
1f5fdd1f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
29 deletion
+37
-29
common/common_windows.go
common/common_windows.go
+23
-7
cpu/cpu_windows.go
cpu/cpu_windows.go
+11
-15
host/host_windows.go
host/host_windows.go
+3
-7
未找到文件。
common/common_windows.go
浏览文件 @
5f8b99aa
...
...
@@ -76,18 +76,34 @@ func BytePtrToString(p *uint8) string {
}
// exec wmic and return lines splited by newline
func
GetWmic
(
target
string
,
query
string
)
([]
string
,
error
)
{
ret
,
err
:=
exec
.
Command
(
"wmic"
,
target
,
"get"
,
query
,
"/format:csv"
)
.
Output
()
func
GetWmic
(
target
string
,
query
...
string
)
([][]
string
,
error
)
{
cmd
:=
[]
string
{
target
}
cmd
=
append
(
cmd
,
query
...
)
cmd
=
append
(
cmd
,
"/format:csv"
)
out
,
err
:=
exec
.
Command
(
"wmic"
,
cmd
...
)
.
Output
()
if
err
!=
nil
{
return
[]
string
{},
err
return
[]
[]
string
{},
err
}
lines
:=
strings
.
Split
(
string
(
re
t
),
"
\r\r\n
"
)
lines
:=
strings
.
Split
(
string
(
ou
t
),
"
\r\r\n
"
)
if
len
(
lines
)
<=
2
{
return
[]
string
{},
fmt
.
Errorf
(
"wmic result malformed: [%q]"
,
lines
)
return
[]
[]
string
{},
fmt
.
Errorf
(
"wmic result malformed: [%q]"
,
lines
)
}
var
ret
[][]
string
for
_
,
l
:=
range
lines
[
2
:
]
{
// skip first two lines
var
lr
[]
string
for
_
,
r
:=
range
strings
.
Split
(
l
,
","
)
{
if
r
==
""
{
continue
}
lr
=
append
(
lr
,
strings
.
TrimSpace
(
r
))
}
if
len
(
lr
)
!=
0
{
ret
=
append
(
ret
,
lr
)
}
}
return
ret
,
nil
// skip first two line
return
lines
[
2
:
],
nil
}
// CounterInfo
...
...
cpu/cpu_windows.go
浏览文件 @
5f8b99aa
...
...
@@ -4,7 +4,6 @@ package cpu
import
(
"strconv"
"strings"
"syscall"
"time"
"unsafe"
...
...
@@ -44,15 +43,11 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
func
CPUInfo
()
([]
CPUInfoStat
,
error
)
{
var
ret
[]
CPUInfoStat
lines
,
err
:=
common
.
GetWmic
(
"cpu"
,
"Family,L2CacheSize,Manufacturer,Name,NumberOfLogicalProcessors,ProcessorId,Stepping"
)
lines
,
err
:=
common
.
GetWmic
(
"cpu"
,
"
get"
,
"
Family,L2CacheSize,Manufacturer,Name,NumberOfLogicalProcessors,ProcessorId,Stepping"
)
if
err
!=
nil
{
return
ret
,
err
}
for
i
,
l
:=
range
lines
{
t
:=
strings
.
Split
(
l
,
","
)
if
len
(
t
)
<
2
{
continue
}
for
i
,
t
:=
range
lines
{
cache
,
err
:=
strconv
.
Atoi
(
t
[
2
])
if
err
!=
nil
{
cache
=
0
...
...
@@ -61,9 +56,12 @@ func CPUInfo() ([]CPUInfoStat, error) {
if
err
!=
nil
{
cores
=
0
}
stepping
,
err
:=
strconv
.
Atoi
(
t
[
7
])
if
err
!=
nil
{
stepping
=
0
stepping
:=
0
if
len
(
t
)
>
7
{
stepping
,
err
=
strconv
.
Atoi
(
t
[
6
])
if
err
!=
nil
{
stepping
=
0
}
}
cpu
:=
CPUInfoStat
{
CPU
:
int32
(
i
),
...
...
@@ -84,17 +82,15 @@ func CPUInfo() ([]CPUInfoStat, error) {
func
CPUPercent
(
interval
time
.
Duration
,
percpu
bool
)
([]
float64
,
error
)
{
ret
:=
[]
float64
{}
lines
,
err
:=
common
.
GetWmic
(
"cpu"
,
"loadpercentage"
)
lines
,
err
:=
common
.
GetWmic
(
"cpu"
,
"
get"
,
"
loadpercentage"
)
if
err
!=
nil
{
return
ret
,
err
}
for
_
,
l
:=
range
lines
{
t
:=
strings
.
Split
(
l
,
","
)
if
len
(
t
)
<
2
{
if
len
(
l
)
<
2
{
continue
}
p
,
err
:=
strconv
.
Atoi
(
t
[
1
])
p
,
err
:=
strconv
.
Atoi
(
l
[
1
])
if
err
!=
nil
{
p
=
0
}
...
...
host/host_windows.go
浏览文件 @
5f8b99aa
...
...
@@ -40,19 +40,15 @@ func HostInfo() (*HostInfoStat, error) {
}
func
BootTime
()
(
uint64
,
error
)
{
lines
,
err
:=
common
.
GetWmic
(
"os"
,
"LastBootUpTime"
)
lines
,
err
:=
common
.
GetWmic
(
"os"
,
"
get"
,
"
LastBootUpTime"
)
if
err
!=
nil
{
return
0
,
err
}
if
len
(
lines
)
==
0
||
l
ines
[
0
]
==
""
{
if
len
(
lines
)
==
0
||
l
en
(
lines
[
0
])
!=
2
{
return
0
,
fmt
.
Errorf
(
"could not get LastBootUpTime"
)
}
l
:=
strings
.
Split
(
lines
[
0
],
","
)
if
len
(
l
)
!=
2
{
return
0
,
fmt
.
Errorf
(
"could not parse LastBootUpTime"
)
}
format
:=
"20060102150405"
t
,
err
:=
time
.
Parse
(
format
,
strings
.
Split
(
l
[
1
],
"."
)[
0
])
t
,
err
:=
time
.
Parse
(
format
,
strings
.
Split
(
l
ines
[
0
]
[
1
],
"."
)[
0
])
if
err
!=
nil
{
return
0
,
err
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录