Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
444ee723
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,发现更多精彩内容 >>
提交
444ee723
编写于
11月 23, 2015
作者:
C
Cameron Sparr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix HostInfo.Uptime, which has been returning boot time
Also adding a HostInfo.BootTime field for holding the boot time
上级
dcbb29ae
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
20 deletion
+65
-20
host/host.go
host/host.go
+1
-0
host/host_darwin.go
host/host_darwin.go
+16
-8
host/host_freebsd.go
host/host_freebsd.go
+16
-7
host/host_linux.go
host/host_linux.go
+16
-2
host/host_windows.go
host/host_windows.go
+16
-3
未找到文件。
host/host.go
浏览文件 @
444ee723
...
...
@@ -9,6 +9,7 @@ import (
type
HostInfoStat
struct
{
Hostname
string
`json:"hostname"`
Uptime
uint64
`json:"uptime"`
BootTime
uint64
`json:"boot_time"`
Procs
uint64
`json:"procs"`
// number of processes
OS
string
`json:"os"`
// ex: freebsd, linux
Platform
string
`json:"platform"`
// ex: ubuntu, linuxmint
...
...
host/host_darwin.go
浏览文件 @
444ee723
...
...
@@ -11,6 +11,7 @@ import (
"runtime"
"strconv"
"strings"
"time"
"unsafe"
"github.com/shirou/gopsutil/internal/common"
...
...
@@ -39,14 +40,10 @@ func HostInfo() (*HostInfoStat, error) {
ret
.
VirtualizationRole
=
role
}
values
,
err
:=
common
.
DoSysctrl
(
"kern.boottime"
)
boot
,
err
:=
BootTime
(
)
if
err
==
nil
{
// ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014
v
:=
strings
.
Replace
(
values
[
2
],
","
,
""
,
1
)
t
,
err
:=
strconv
.
ParseUint
(
v
,
10
,
64
)
if
err
!=
nil
{
ret
.
Uptime
=
t
}
ret
.
BootTime
=
boot
ret
.
Uptime
=
uptime
(
boot
)
}
return
ret
,
nil
...
...
@@ -59,7 +56,6 @@ func BootTime() (uint64, error) {
}
// ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014
v
:=
strings
.
Replace
(
values
[
2
],
","
,
""
,
1
)
boottime
,
err
:=
strconv
.
ParseInt
(
v
,
10
,
64
)
if
err
!=
nil
{
return
0
,
err
...
...
@@ -68,6 +64,18 @@ func BootTime() (uint64, error) {
return
uint64
(
boottime
),
nil
}
func
uptime
(
boot
uint64
)
uint64
{
return
uint64
(
time
.
Now
()
.
Unix
())
-
boot
}
func
Uptime
()
(
uint64
,
error
)
{
boot
,
err
:=
BootTime
()
if
err
!=
nil
{
return
0
,
err
}
return
uptime
(
boot
),
nil
}
func
Users
()
([]
UserStat
,
error
)
{
utmpfile
:=
"/var/run/utmpx"
var
ret
[]
UserStat
...
...
host/host_freebsd.go
浏览文件 @
444ee723
...
...
@@ -11,6 +11,7 @@ import (
"runtime"
"strconv"
"strings"
"time"
"unsafe"
"github.com/shirou/gopsutil/internal/common"
...
...
@@ -45,14 +46,10 @@ func HostInfo() (*HostInfoStat, error) {
ret
.
VirtualizationRole
=
role
}
values
,
err
:=
common
.
DoSysctrl
(
"kern.boottime"
)
boot
,
err
:=
BootTime
(
)
if
err
==
nil
{
// ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014
v
:=
strings
.
Replace
(
values
[
2
],
","
,
""
,
1
)
t
,
err
:=
strconv
.
ParseUint
(
v
,
10
,
64
)
if
err
==
nil
{
ret
.
Uptime
=
t
}
ret
.
BootTime
=
boot
ret
.
Uptime
=
uptime
(
boot
)
}
return
ret
,
nil
...
...
@@ -74,6 +71,18 @@ func BootTime() (int64, error) {
return
boottime
,
nil
}
func
uptime
(
boot
uint64
)
uint64
{
return
uint64
(
time
.
Now
()
.
Unix
())
-
boot
}
func
Uptime
()
(
uint64
,
error
)
{
boot
,
err
:=
BootTime
()
if
err
!=
nil
{
return
0
,
err
}
return
uptime
(
boot
),
nil
}
func
Users
()
([]
UserStat
,
error
)
{
utmpfile
:=
"/var/run/utx.active"
if
!
common
.
PathExists
(
utmpfile
)
{
...
...
host/host_linux.go
浏览文件 @
444ee723
...
...
@@ -13,6 +13,7 @@ import (
"runtime"
"strconv"
"strings"
"time"
"unsafe"
"github.com/shirou/gopsutil/internal/common"
...
...
@@ -46,9 +47,10 @@ func HostInfo() (*HostInfoStat, error) {
ret
.
VirtualizationSystem
=
system
ret
.
VirtualizationRole
=
role
}
uptime
,
err
:=
BootTime
()
boot
,
err
:=
BootTime
()
if
err
==
nil
{
ret
.
Uptime
=
uptime
ret
.
BootTime
=
boot
ret
.
Uptime
=
uptime
(
boot
)
}
return
ret
,
nil
...
...
@@ -78,6 +80,18 @@ func BootTime() (uint64, error) {
return
0
,
fmt
.
Errorf
(
"could not find btime"
)
}
func
uptime
(
boot
uint64
)
uint64
{
return
uint64
(
time
.
Now
()
.
Unix
())
-
boot
}
func
Uptime
()
(
uint64
,
error
)
{
boot
,
err
:=
BootTime
()
if
err
!=
nil
{
return
0
,
err
}
return
uptime
(
boot
),
nil
}
func
Users
()
([]
UserStat
,
error
)
{
utmpfile
:=
"/var/run/utmp"
...
...
host/host_windows.go
浏览文件 @
444ee723
...
...
@@ -47,9 +47,10 @@ func HostInfo() (*HostInfoStat, error) {
return
ret
,
err
}
ret
.
Uptime
,
err
=
BootTime
()
if
err
!=
nil
{
return
ret
,
err
boot
,
err
:=
BootTime
()
if
err
==
nil
{
ret
.
BootTime
=
boot
ret
.
Uptime
=
uptime
(
boot
)
}
procs
,
err
:=
process
.
Pids
()
...
...
@@ -87,6 +88,18 @@ func BootTime() (uint64, error) {
return
uint64
(
now
.
Sub
(
t
)
.
Seconds
()),
nil
}
func
uptime
(
boot
uint64
)
uint64
{
return
uint64
(
time
.
Now
()
.
Unix
())
-
boot
}
func
Uptime
()
(
uint64
,
error
)
{
boot
,
err
:=
BootTime
()
if
err
!=
nil
{
return
0
,
err
}
return
uptime
(
boot
),
nil
}
func
GetPlatformInformation
()
(
platform
string
,
family
string
,
version
string
,
err
error
)
{
if
osInfo
==
nil
{
_
,
err
=
GetOSInfo
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录