update pkg and version

This commit is contained in:
vcaesar 2018-03-24 21:15:21 +08:00
parent e48c1ea1d1
commit 8865d93a65
15 changed files with 188 additions and 133 deletions

View File

@ -65,7 +65,7 @@ import (
) )
const ( const (
version string = "v0.48.0.534, Ben Nevis!" version string = "v0.48.0.540, Ben Nevis!"
) )
type ( type (

View File

@ -54,10 +54,9 @@ type lastPercent struct {
} }
var lastCPUPercent lastPercent var lastCPUPercent lastPercent
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() { func init() {
invoke = common.Invoke{}
lastCPUPercent.Lock() lastCPUPercent.Lock()
lastCPUPercent.lastCPUTimes, _ = Times(false) lastCPUPercent.lastCPUTimes, _ = Times(false)
lastCPUPercent.lastPerCPUTimes, _ = Times(true) lastCPUPercent.lastPerCPUTimes, _ = Times(true)

View File

@ -6,11 +6,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
// A HostInfoStat describes the host status. // A HostInfoStat describes the host status.
// This is not in the psutil but it useful. // This is not in the psutil but it useful.

View File

@ -55,3 +55,11 @@ func KernelVersion() (string, error) {
func KernelVersionWithContext(ctx context.Context) (string, error) { func KernelVersionWithContext(ctx context.Context) (string, error) {
return "", common.ErrNotImplementedError return "", common.ErrNotImplementedError
} }
func PlatformInformation() (string, string, string, error) {
return PlatformInformationWithContext(context.Background())
}
func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) {
return "", "", "", common.ErrNotImplementedError
}

View File

@ -8,7 +8,6 @@ import (
"encoding/binary" "encoding/binary"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"runtime" "runtime"
"strings" "strings"
"sync/atomic" "sync/atomic"
@ -168,25 +167,17 @@ func PlatformInformation() (string, string, string, error) {
} }
func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) {
platform := "" platform, err := unix.Sysctl("kern.ostype")
family := ""
version := ""
uname, err := exec.LookPath("uname")
if err != nil { if err != nil {
return "", "", "", err return "", "", "", err
} }
out, err := invoke.Command(uname, "-s") version, err := unix.Sysctl("kern.osrelease")
if err == nil { if err != nil {
platform = strings.ToLower(strings.TrimSpace(string(out))) return "", "", "", err
} }
out, err = invoke.Command(uname, "-r") return strings.ToLower(platform), "", strings.ToLower(version), nil
if err == nil {
version = strings.ToLower(strings.TrimSpace(string(out)))
}
return platform, family, version, nil
} }
func Virtualization() (string, string, error) { func Virtualization() (string, string, error) {

View File

@ -109,10 +109,14 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
statFile := "stat" statFile := "stat"
if system == "lxc" && role == "guest" { if system == "lxc" && role == "guest" {
// if lxc, /proc/uptime is used. // if lxc, /proc/uptime is used.
statFile = "uptime" statFile = "uptime"
} else if system == "docker" && role == "guest" {
// also docker, guest
statFile = "uptime"
} }
filename := common.HostProc(statFile) filename := common.HostProc(statFile)
@ -120,6 +124,8 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
if statFile == "stat" {
for _, line := range lines { for _, line := range lines {
if strings.HasPrefix(line, "btime") { if strings.HasPrefix(line, "btime") {
f := strings.Fields(line) f := strings.Fields(line)
@ -135,6 +141,19 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
return t, nil return t, nil
} }
} }
} else if statFile == "uptime" {
if len(lines) != 1 {
return 0, fmt.Errorf("wrong uptime format")
}
f := strings.Fields(lines[0])
b, err := strconv.ParseInt(f[0], 10, 64)
if err != nil {
return 0, err
}
t = uint64(time.Now().Unix()) - uint64(b)
atomic.StoreUint64(&cachedBootTime, t)
return t, nil
}
return 0, fmt.Errorf("could not find btime") return 0, fmt.Errorf("could not find btime")
} }

View File

@ -231,3 +231,18 @@ func KernelVersionWithContext(ctx context.Context) (string, error) {
} }
return "", fmt.Errorf("could not get kernel version") return "", fmt.Errorf("could not get kernel version")
} }
func PlatformInformation() (platform string, family string, version string, err error) {
return PlatformInformationWithContext(context.Background())
}
func PlatformInformationWithContext(ctx context.Context) (platform string, family string, version string, err error) {
/* This is not finished yet at all. Please contribute! */
version, err = KernelVersion()
if err != nil {
return "", "", "", err
}
return "solaris", "solaris", version, nil
}

View File

@ -6,11 +6,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
// Memory usage statistics. Total, Available and Used contain numbers of bytes // Memory usage statistics. Total, Available and Used contain numbers of bytes
// for human consumption. // for human consumption.

View File

@ -5,9 +5,7 @@ package mem
import ( import (
"context" "context"
"errors" "errors"
"os/exec" "unsafe"
"strconv"
"strings"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -69,53 +67,66 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
} }
// Return swapinfo // Return swapinfo
// FreeBSD can have multiple swap devices. but use only first device
func SwapMemory() (*SwapMemoryStat, error) { func SwapMemory() (*SwapMemoryStat, error) {
return SwapMemoryWithContext(context.Background()) return SwapMemoryWithContext(context.Background())
} }
func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { // Constants from vm/vm_param.h
swapinfo, err := exec.LookPath("swapinfo") // nolint: golint
if err != nil { const (
return nil, err XSWDEV_VERSION = 1
} )
out, err := invoke.Command(swapinfo) // Types from vm/vm_param.h
if err != nil { type xswdev struct {
return nil, err Version uint32 // Version is the version
} Dev uint32 // Dev is the device identifier
for _, line := range strings.Split(string(out), "\n") { Flags int32 // Flags is the swap flags applied to the device
values := strings.Fields(line) NBlks int32 // NBlks is the total number of blocks
// skip title line Used int32 // Used is the number of blocks used
if len(values) == 0 || values[0] == "Device" { }
continue
} func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
// FreeBSD can have multiple swap devices so we total them up
u := strings.Replace(values[4], "%", "", 1) i, err := unix.SysctlUint32("vm.nswapdev")
total_v, err := strconv.ParseUint(values[1], 10, 64) if err != nil {
if err != nil { return nil, err
return nil, err }
}
used_v, err := strconv.ParseUint(values[2], 10, 64) if i == 0 {
if err != nil { return nil, errors.New("no swap devices found")
return nil, err }
}
free_v, err := strconv.ParseUint(values[3], 10, 64) c := int(i)
if err != nil {
return nil, err i, err = unix.SysctlUint32("vm.stats.vm.v_page_size")
} if err != nil {
up_v, err := strconv.ParseFloat(u, 64) return nil, err
if err != nil { }
return nil, err pageSize := uint64(i)
}
var buf []byte
return &SwapMemoryStat{ s := &SwapMemoryStat{}
Total: total_v, for n := 0; n < c; n++ {
Used: used_v, buf, err = unix.SysctlRaw("vm.swap_info", n)
Free: free_v, if err != nil {
UsedPercent: up_v, return nil, err
}, nil }
}
xsw := (*xswdev)(unsafe.Pointer(&buf[0]))
return nil, errors.New("no swap devices found") if xsw.Version != XSWDEV_VERSION {
return nil, errors.New("xswdev version mismatch")
}
s.Total += uint64(xsw.NBlks)
s.Used += uint64(xsw.Used)
}
if s.Total != 0 {
s.UsedPercent = float64(s.Used) / float64(s.Total) * 100
}
s.Total *= pageSize
s.Used *= pageSize
s.Free = s.Total - s.Used
return s, nil
} }

View File

@ -12,11 +12,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
type IOCountersStat struct { type IOCountersStat struct {
Name string `json:"name"` // interface name Name string `json:"name"` // interface name

View File

@ -3,6 +3,7 @@ package process
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"runtime" "runtime"
"time" "time"
@ -11,11 +12,10 @@ import (
"github.com/shirou/gopsutil/mem" "github.com/shirou/gopsutil/mem"
) )
var invoke common.Invoker var (
invoke common.Invoker = common.Invoke{}
func init() { ErrorNoChildren = errors.New("process does not have children")
invoke = common.Invoke{} )
}
type Process struct { type Process struct {
Pid int32 `json:"pid"` Pid int32 `json:"pid"`

View File

@ -7,7 +7,6 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math" "math"
@ -23,10 +22,7 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
var ( var PageSize = uint64(os.Getpagesize())
ErrorNoChildren = errors.New("process does not have children")
PageSize = uint64(os.Getpagesize())
)
const ( const (
PrioProcess = 0 // linux/resource.h PrioProcess = 0 // linux/resource.h

View File

@ -1,9 +1,9 @@
# img # img
[![CircleCI Status](https://circleci.com/gh/vcaesar/img.svg?style=shield)](https://circleci.com/gh/vcaesar/img) [![CircleCI Status](https://circleci.com/gh/vcaesar/imgo.svg?style=shield)](https://circleci.com/gh/vcaesar/imgo)
[![codecov](https://codecov.io/gh/vcaesar/img/branch/master/graph/badge.svg)](https://codecov.io/gh/vcaesar/img) [![codecov](https://codecov.io/gh/vcaesar/imgo/branch/master/graph/badge.svg)](https://codecov.io/gh/vcaesar/imgo)
[![Build Status](https://travis-ci.org/vcaesar/img.svg)](https://travis-ci.org/vcaesar/img) [![Build Status](https://travis-ci.org/vcaesar/imgo.svg)](https://travis-ci.org/vcaesar/imgo)
[![Go Report Card](https://goreportcard.com/badge/github.com/vcaesar/img)](https://goreportcard.com/report/github.com/vcaesar/img) [![Go Report Card](https://goreportcard.com/badge/github.com/vcaesar/imgo)](https://goreportcard.com/report/github.com/vcaesar/imgo)
[![GoDoc](https://godoc.org/github.com/vcaesar/img?status.svg)](https://godoc.org/github.com/vcaesar/img) [![GoDoc](https://godoc.org/github.com/vcaesar/imgo?status.svg)](https://godoc.org/github.com/vcaesar/imgo)
[![Release](https://github-release-version.herokuapp.com/github/vcaesar/img/release.svg?style=flat)](https://github.com/vcaesar/img/releases/latest) [![Release](https://github-release-version.herokuapp.com/github/vcaesar/imgo/release.svg?style=flat)](https://github.com/vcaesar/imgo/releases/latest)
[![Join the chat at https://gitter.im/go-vgo/robotgo](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-vgo/robotgo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/go-vgo/robotgo](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-vgo/robotgo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

View File

@ -1,9 +1,9 @@
# img # img
[![CircleCI Status](https://circleci.com/gh/vcaesar/img.svg?style=shield)](https://circleci.com/gh/vcaesar/img) [![CircleCI Status](https://circleci.com/gh/vcaesar/imgo.svg?style=shield)](https://circleci.com/gh/vcaesar/imgo)
[![codecov](https://codecov.io/gh/vcaesar/img/branch/master/graph/badge.svg)](https://codecov.io/gh/vcaesar/img) [![codecov](https://codecov.io/gh/vcaesar/imgo/branch/master/graph/badge.svg)](https://codecov.io/gh/vcaesar/imgo)
[![Build Status](https://travis-ci.org/vcaesar/img.svg)](https://travis-ci.org/vcaesar/img) [![Build Status](https://travis-ci.org/vcaesar/imgo.svg)](https://travis-ci.org/vcaesar/imgo)
[![Go Report Card](https://goreportcard.com/badge/github.com/vcaesar/img)](https://goreportcard.com/report/github.com/vcaesar/img) [![Go Report Card](https://goreportcard.com/badge/github.com/vcaesar/imgo)](https://goreportcard.com/report/github.com/vcaesar/imgo)
[![GoDoc](https://godoc.org/github.com/vcaesar/img?status.svg)](https://godoc.org/github.com/vcaesar/img) [![GoDoc](https://godoc.org/github.com/vcaesar/imgo?status.svg)](https://godoc.org/github.com/vcaesar/imgo)
[![Release](https://github-release-version.herokuapp.com/github/vcaesar/img/release.svg?style=flat)](https://github.com/vcaesar/img/releases/latest) [![Release](https://github-release-version.herokuapp.com/github/vcaesar/imgo/release.svg?style=flat)](https://github.com/vcaesar/imgo/releases/latest)
[![Join the chat at https://gitter.im/go-vgo/robotgo](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-vgo/robotgo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/go-vgo/robotgo](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-vgo/robotgo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

68
vendor/vendor.json vendored
View File

@ -45,40 +45,40 @@
"revisionTime": "2017-07-14T06:33:53Z" "revisionTime": "2017-07-14T06:33:53Z"
}, },
{ {
"checksumSHA1": "PHwqGzRGjJ81TtD7aBgcppCjeRg=", "checksumSHA1": "cspJvF0E9whCLlbX8MlrYemtOzo=",
"path": "github.com/shirou/gopsutil/cpu", "path": "github.com/shirou/gopsutil/cpu",
"revision": "5776ff9c7c5d063d574ef53d740f75c68b448e53", "revision": "b99342a9ceb013854c12cfb0b55c2adc57837a29",
"revisionTime": "2018-02-27T22:58:47Z" "revisionTime": "2018-03-24T06:57:29Z"
}, },
{ {
"checksumSHA1": "sy4twPdTy18BS0k2PxntChG2FcE=", "checksumSHA1": "X93ayElJyx5k/xOUSMzMdYIbQ7M=",
"path": "github.com/shirou/gopsutil/host", "path": "github.com/shirou/gopsutil/host",
"revision": "5776ff9c7c5d063d574ef53d740f75c68b448e53", "revision": "b99342a9ceb013854c12cfb0b55c2adc57837a29",
"revisionTime": "2018-02-27T22:58:47Z" "revisionTime": "2018-03-24T06:57:29Z"
}, },
{ {
"checksumSHA1": "xPMr7RbEnFd1XxOFpLOSdX4cEO0=", "checksumSHA1": "xPMr7RbEnFd1XxOFpLOSdX4cEO0=",
"path": "github.com/shirou/gopsutil/internal/common", "path": "github.com/shirou/gopsutil/internal/common",
"revision": "5776ff9c7c5d063d574ef53d740f75c68b448e53", "revision": "b99342a9ceb013854c12cfb0b55c2adc57837a29",
"revisionTime": "2018-02-27T22:58:47Z" "revisionTime": "2018-03-24T06:57:29Z"
}, },
{ {
"checksumSHA1": "Cgm7wMq9rJpnUeZFV3OD8qkTKOM=", "checksumSHA1": "s/McZHJfB9Kt5lyI2VccZ8yUaW0=",
"path": "github.com/shirou/gopsutil/mem", "path": "github.com/shirou/gopsutil/mem",
"revision": "5776ff9c7c5d063d574ef53d740f75c68b448e53", "revision": "b99342a9ceb013854c12cfb0b55c2adc57837a29",
"revisionTime": "2018-02-27T22:58:47Z" "revisionTime": "2018-03-24T06:57:29Z"
}, },
{ {
"checksumSHA1": "Z7FjZvR5J5xh6Ne572gD7tRUsc8=", "checksumSHA1": "cfj8JcHTkICoDEj6AAuniOi48FA=",
"path": "github.com/shirou/gopsutil/net", "path": "github.com/shirou/gopsutil/net",
"revision": "5776ff9c7c5d063d574ef53d740f75c68b448e53", "revision": "b99342a9ceb013854c12cfb0b55c2adc57837a29",
"revisionTime": "2018-02-27T22:58:47Z" "revisionTime": "2018-03-24T06:57:29Z"
}, },
{ {
"checksumSHA1": "l372fZbcjJ2OlVmg0JihEjbtUcE=", "checksumSHA1": "IkOLZLYKoKuA1rVTJtPcgGGMA0Y=",
"path": "github.com/shirou/gopsutil/process", "path": "github.com/shirou/gopsutil/process",
"revision": "5776ff9c7c5d063d574ef53d740f75c68b448e53", "revision": "b99342a9ceb013854c12cfb0b55c2adc57837a29",
"revisionTime": "2018-02-27T22:58:47Z" "revisionTime": "2018-03-24T06:57:29Z"
}, },
{ {
"checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=", "checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=",
@ -103,15 +103,19 @@
"revisionTime": "2017-06-01T20:57:54Z" "revisionTime": "2017-06-01T20:57:54Z"
}, },
{ {
"checksumSHA1": "uZ3mletGtExUozsdwpZ+B4KmFXk=", "checksumSHA1": "qqYvzeNRTp9tXZwP2IBx/euloqo=",
"path": "github.com/vcaesar/imgo", "path": "github.com/vcaesar/imgo",
"revision": "67f0b2002c0030cda52e4cf2bd8b9e5826adf6e5", "revision": "fece97d8745e9e2299516bf074772fccf03a53a5",
"revisionTime": "2018-03-04T12:31:00Z" "revisionTime": "2018-03-07T10:09:24Z"
}, },
{ {
"path": "golang.org/x/image/bmp", "path": "golang.org/x/image/bmp",
"revision": "" "revision": ""
}, },
{
"path": "golang.org/x/sys/plan9",
"revision": ""
},
{ {
"checksumSHA1": "EL5tiYbzPcSM0nhJpvMSDnDNvxI=", "checksumSHA1": "EL5tiYbzPcSM0nhJpvMSDnDNvxI=",
"path": "golang.org/x/sys/unix", "path": "golang.org/x/sys/unix",
@ -123,6 +127,30 @@
"path": "golang.org/x/sys/windows", "path": "golang.org/x/sys/windows",
"revision": "4ed4d404df456f81e878683a0363ed3013a59003", "revision": "4ed4d404df456f81e878683a0363ed3013a59003",
"revisionTime": "2017-06-30T13:23:30Z" "revisionTime": "2017-06-30T13:23:30Z"
},
{
"path": "golang.org/x/sys/windows/registry",
"revision": ""
},
{
"path": "golang.org/x/sys/windows/svc",
"revision": ""
},
{
"path": "golang.org/x/sys/windows/svc/debug",
"revision": ""
},
{
"path": "golang.org/x/sys/windows/svc/eventlog",
"revision": ""
},
{
"path": "golang.org/x/sys/windows/svc/example",
"revision": ""
},
{
"path": "golang.org/x/sys/windows/svc/mgr",
"revision": ""
} }
], ],
"rootPath": "github.com/go-vgo/robotgo" "rootPath": "github.com/go-vgo/robotgo"