Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
4b0f5a03
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,发现更多精彩内容 >>
提交
4b0f5a03
编写于
2月 15, 2015
作者:
W
WAKAYAMA Shirou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
host: use wmic OS instead of calling GetTickCount on Windows.
上级
4694ce0e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
32 deletion
+31
-32
README.rst
README.rst
+8
-8
host/host_windows.go
host/host_windows.go
+23
-24
未找到文件。
README.rst
浏览文件 @
4b0f5a03
...
...
@@ -128,7 +128,7 @@ Current Status
================= ====== ======= ====== =======
name Linux FreeBSD MacOSX Windows
cpu_times x x
cpu_times x x
x
cpu_count x x x x
cpu_percent x x x
cpu_times_percent x x x
...
...
@@ -138,7 +138,7 @@ disk_partitions x x x x
disk_io_counters x
disk_usage x x x x
net_io_counters x x b x
boot_time x x x
b
boot_time x x x
x
users x x x x
pids x x x x
pid_exists x x x x
...
...
@@ -202,14 +202,14 @@ hostname x x x x
platformfamiliy x x x
virtualization x
**CPU**
VendorID x x x
Family x x x
Model x x x
Stepping x x x
VendorID x x x
x
Family x x x
x
Model x x x
x
Stepping x x x
x
PhysicalID x
CoreID x
Cores x
ModelName x x x
Cores x
x
ModelName x x x
x
**LoadAvg**
Load1 x x x
Load5 x x x
...
...
host/host_windows.go
浏览文件 @
4b0f5a03
...
...
@@ -3,9 +3,10 @@
package
host
import
(
"fmt"
"os"
"s
yscall
"
"
unsaf
e"
"s
trings
"
"
tim
e"
common
"github.com/shirou/gopsutil/common"
process
"github.com/shirou/gopsutil/process"
...
...
@@ -13,7 +14,6 @@ import (
var
(
procGetSystemTimeAsFileTime
=
common
.
Modkernel32
.
NewProc
(
"GetSystemTimeAsFileTime"
)
procGetTickCount
=
common
.
Modkernel32
.
NewProc
(
"GetTickCount"
)
)
func
HostInfo
()
(
*
HostInfoStat
,
error
)
{
...
...
@@ -24,13 +24,11 @@ func HostInfo() (*HostInfoStat, error) {
}
ret
.
Hostname
=
hostname
uptime
msec
,
_
,
err
:=
procGetTickCount
.
Call
()
if
uptimemsec
==
0
{
ret
urn
ret
,
syscall
.
GetLastError
()
uptime
,
err
:=
BootTime
()
if
err
==
nil
{
ret
.
Uptime
=
uptime
}
ret
.
Uptime
=
uint64
(
uptimemsec
)
/
1000
procs
,
err
:=
process
.
Pids
()
if
err
!=
nil
{
return
ret
,
err
...
...
@@ -42,25 +40,26 @@ func HostInfo() (*HostInfoStat, error) {
}
func
BootTime
()
(
uint64
,
error
)
{
var
lpSystemTimeAsFileTime
common
.
FILETIME
r
,
_
,
_
:=
procGetSystemTimeAsFileTime
.
Call
(
uintptr
(
unsafe
.
Pointer
(
&
lpSystemTimeAsFileTime
)))
if
r
==
0
{
return
0
,
syscall
.
GetLastError
()
lines
,
err
:=
common
.
GetWmic
(
"os"
,
"LastBootUpTime"
)
if
err
!=
nil
{
return
0
,
err
}
// TODO: This calc is wrong.
ll
:=
(
uint32
(
lpSystemTimeAsFileTime
.
DwHighDateTime
))
<<
32
+
lpSystemTimeAsFileTime
.
DwLowDateTime
pt
:=
(
uint64
(
ll
)
-
116444736000000000
)
/
10000000
u
,
_
,
_
:=
procGetTickCount
.
Call
()
if
u
==
0
{
return
0
,
syscall
.
GetLastError
()
if
len
(
lines
)
==
0
||
lines
[
0
]
==
""
{
return
0
,
fmt
.
Errorf
(
"could not get LastBootUpTime"
)
}
uptime
:=
uint64
(
u
)
/
1000
return
uint64
(
pt
-
uptime
),
nil
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
])
if
err
!=
nil
{
return
0
,
err
}
now
:=
time
.
Now
()
return
uint64
(
now
.
Sub
(
t
)
.
Seconds
()),
nil
}
func
Users
()
([]
UserStat
,
error
)
{
var
ret
[]
UserStat
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录