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 (
version string = "v0.48.0.534, Ben Nevis!"
version string = "v0.48.0.540, Ben Nevis!"
)
type (

View File

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

View File

@ -6,11 +6,7 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
var invoke common.Invoker
func init() {
invoke = common.Invoke{}
}
var invoke common.Invoker = common.Invoke{}
// A HostInfoStat describes the host status.
// 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) {
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"
"io/ioutil"
"os"
"os/exec"
"runtime"
"strings"
"sync/atomic"
@ -168,25 +167,17 @@ func PlatformInformation() (string, string, string, error) {
}
func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) {
platform := ""
family := ""
version := ""
uname, err := exec.LookPath("uname")
platform, err := unix.Sysctl("kern.ostype")
if err != nil {
return "", "", "", err
}
out, err := invoke.Command(uname, "-s")
if err == nil {
platform = strings.ToLower(strings.TrimSpace(string(out)))
version, err := unix.Sysctl("kern.osrelease")
if err != nil {
return "", "", "", err
}
out, err = invoke.Command(uname, "-r")
if err == nil {
version = strings.ToLower(strings.TrimSpace(string(out)))
}
return platform, family, version, nil
return strings.ToLower(platform), "", strings.ToLower(version), nil
}
func Virtualization() (string, string, error) {

View File

@ -109,10 +109,14 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
if err != nil {
return 0, err
}
statFile := "stat"
if system == "lxc" && role == "guest" {
// if lxc, /proc/uptime is used.
statFile = "uptime"
} else if system == "docker" && role == "guest" {
// also docker, guest
statFile = "uptime"
}
filename := common.HostProc(statFile)
@ -120,20 +124,35 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
if err != nil {
return 0, err
}
for _, line := range lines {
if strings.HasPrefix(line, "btime") {
f := strings.Fields(line)
if len(f) != 2 {
return 0, fmt.Errorf("wrong btime format")
if statFile == "stat" {
for _, line := range lines {
if strings.HasPrefix(line, "btime") {
f := strings.Fields(line)
if len(f) != 2 {
return 0, fmt.Errorf("wrong btime format")
}
b, err := strconv.ParseInt(f[1], 10, 64)
if err != nil {
return 0, err
}
t = uint64(b)
atomic.StoreUint64(&cachedBootTime, t)
return t, nil
}
b, err := strconv.ParseInt(f[1], 10, 64)
if err != nil {
return 0, err
}
t = uint64(b)
atomic.StoreUint64(&cachedBootTime, t)
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")

View File

@ -231,3 +231,18 @@ func KernelVersionWithContext(ctx context.Context) (string, error) {
}
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"
)
var invoke common.Invoker
func init() {
invoke = common.Invoke{}
}
var invoke common.Invoker = common.Invoke{}
// Memory usage statistics. Total, Available and Used contain numbers of bytes
// for human consumption.

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
# img
[![CircleCI Status](https://circleci.com/gh/vcaesar/img.svg?style=shield)](https://circleci.com/gh/vcaesar/img)
[![codecov](https://codecov.io/gh/vcaesar/img/branch/master/graph/badge.svg)](https://codecov.io/gh/vcaesar/img)
[![Build Status](https://travis-ci.org/vcaesar/img.svg)](https://travis-ci.org/vcaesar/img)
[![Go Report Card](https://goreportcard.com/badge/github.com/vcaesar/img)](https://goreportcard.com/report/github.com/vcaesar/img)
[![GoDoc](https://godoc.org/github.com/vcaesar/img?status.svg)](https://godoc.org/github.com/vcaesar/img)
[![Release](https://github-release-version.herokuapp.com/github/vcaesar/img/release.svg?style=flat)](https://github.com/vcaesar/img/releases/latest)
[![CircleCI Status](https://circleci.com/gh/vcaesar/imgo.svg?style=shield)](https://circleci.com/gh/vcaesar/imgo)
[![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/imgo.svg)](https://travis-ci.org/vcaesar/imgo)
[![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/imgo?status.svg)](https://godoc.org/github.com/vcaesar/imgo)
[![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)

View File

@ -1,9 +1,9 @@
# img
[![CircleCI Status](https://circleci.com/gh/vcaesar/img.svg?style=shield)](https://circleci.com/gh/vcaesar/img)
[![codecov](https://codecov.io/gh/vcaesar/img/branch/master/graph/badge.svg)](https://codecov.io/gh/vcaesar/img)
[![Build Status](https://travis-ci.org/vcaesar/img.svg)](https://travis-ci.org/vcaesar/img)
[![Go Report Card](https://goreportcard.com/badge/github.com/vcaesar/img)](https://goreportcard.com/report/github.com/vcaesar/img)
[![GoDoc](https://godoc.org/github.com/vcaesar/img?status.svg)](https://godoc.org/github.com/vcaesar/img)
[![Release](https://github-release-version.herokuapp.com/github/vcaesar/img/release.svg?style=flat)](https://github.com/vcaesar/img/releases/latest)
[![CircleCI Status](https://circleci.com/gh/vcaesar/imgo.svg?style=shield)](https://circleci.com/gh/vcaesar/imgo)
[![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/imgo.svg)](https://travis-ci.org/vcaesar/imgo)
[![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/imgo?status.svg)](https://godoc.org/github.com/vcaesar/imgo)
[![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)

68
vendor/vendor.json vendored
View File

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