Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit

Permalink
fixed by golint.
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Apr 1, 2016
1 parent 944429d commit 613a8a9
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 127 deletions.
4 changes: 2 additions & 2 deletions cpu/cpu_darwin_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package cpu
import "github.com/shirou/gopsutil/internal/common"

func perCPUTimes() ([]TimesStat, error) {
return []TimesStat{}, common.NotImplementedError
return []TimesStat{}, common.ErrNotImplementedError
}

func allCPUTimes() ([]TimesStat, error) {
return []TimesStat{}, common.NotImplementedError
return []TimesStat{}, common.ErrNotImplementedError
}
8 changes: 4 additions & 4 deletions cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Times(percpu bool) ([]TimesStat, error) {
break
}
lines = append(lines, line)
startIdx += 1
startIdx++
}
} else {
lines, _ = common.ReadLinesOffsetN(filename, 0, 1)
Expand All @@ -56,13 +56,13 @@ func Times(percpu bool) ([]TimesStat, error) {
return ret, nil
}

func sysCpuPath(cpu int32, relPath string) string {
func sysCPUPath(cpu int32, relPath string) string {
return common.HostSys(fmt.Sprintf("devices/system/cpu/cpu%d", cpu), relPath)
}

func finishCPUInfo(c *InfoStat) error {
if c.Mhz == 0 {
lines, err := common.ReadLines(sysCpuPath(c.CPU, "cpufreq/cpuinfo_max_freq"))
lines, err := common.ReadLines(sysCPUPath(c.CPU, "cpufreq/cpuinfo_max_freq"))
if err == nil {
value, err := strconv.ParseFloat(lines[0], 64)
if err != nil {
Expand All @@ -72,7 +72,7 @@ func finishCPUInfo(c *InfoStat) error {
}
}
if len(c.CoreID) == 0 {
lines, err := common.ReadLines(sysCpuPath(c.CPU, "topology/coreId"))
lines, err := common.ReadLines(sysCPUPath(c.CPU, "topology/coreId"))
if err == nil {
c.CoreID = lines[0]
}
Expand Down
6 changes: 3 additions & 3 deletions cpu/cpu_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Win32_Processor struct {
Manufacturer string
Name string
NumberOfLogicalProcessors uint32
ProcessorId *string
ProcessorID *string
Stepping *string
MaxClockSpeed uint32
}
Expand Down Expand Up @@ -66,8 +66,8 @@ func Info() ([]InfoStat, error) {
var procID string
for i, l := range dst {
procID = ""
if l.ProcessorId != nil {
procID = *l.ProcessorId
if l.ProcessorID != nil {
procID = *l.ProcessorID
}

cpu := InfoStat{
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Partitions(all bool) ([]PartitionStat, error) {
}

func IOCounters() (map[string]IOCountersStat, error) {
return nil, common.NotImplementedError
return nil, common.ErrNotImplementedError
}

func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
Expand Down
51 changes: 25 additions & 26 deletions docker/docker_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ func GetDockerIDList() ([]string, error) {
}

// CgroupCPU returnes specified cgroup id CPU status.
// containerId is same as docker id if you use docker.
// containerID is same as docker id if you use docker.
// If you use container via systemd.slice, you could use
// containerId = docker-<container id>.scope and base=/sys/fs/cgroup/cpuacct/system.slice/
func CgroupCPU(containerId string, base string) (*cpu.TimesStat, error) {
statfile := getCgroupFilePath(containerId, base, "cpuacct", "cpuacct.stat")
// containerID = docker-<container id>.scope and base=/sys/fs/cgroup/cpuacct/system.slice/
func CgroupCPU(containerID string, base string) (*cpu.TimesStat, error) {
statfile := getCgroupFilePath(containerID, base, "cpuacct", "cpuacct.stat")
lines, err := common.ReadLines(statfile)
if err != nil {
return nil, err
}
// empty containerId means all cgroup
if len(containerId) == 0 {
containerId = "all"
// empty containerID means all cgroup
if len(containerID) == 0 {
containerID = "all"
}
ret := &cpu.TimesStat{CPU: containerId}
ret := &cpu.TimesStat{CPU: containerID}
for _, line := range lines {
fields := strings.Split(line, " ")
if fields[0] == "user" {
Expand All @@ -78,18 +78,18 @@ func CgroupCPUDocker(containerid string) (*cpu.TimesStat, error) {
return CgroupCPU(containerid, common.HostSys("fs/cgroup/cpuacct/docker"))
}

func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
statfile := getCgroupFilePath(containerId, base, "memory", "memory.stat")
func CgroupMem(containerID string, base string) (*CgroupMemStat, error) {
statfile := getCgroupFilePath(containerID, base, "memory", "memory.stat")

// empty containerId means all cgroup
if len(containerId) == 0 {
containerId = "all"
// empty containerID means all cgroup
if len(containerID) == 0 {
containerID = "all"
}
lines, err := common.ReadLines(statfile)
if err != nil {
return nil, err
}
ret := &CgroupMemStat{ContainerID: containerId}
ret := &CgroupMemStat{ContainerID: containerID}
for _, line := range lines {
fields := strings.Split(line, " ")
v, err := strconv.ParseUint(fields[1], 10, 64)
Expand Down Expand Up @@ -154,28 +154,28 @@ func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
}
}

r, err := getCgroupMemFile(containerId, base, "memory.usage_in_bytes")
r, err := getCgroupMemFile(containerID, base, "memory.usage_in_bytes")
if err == nil {
ret.MemUsageInBytes = r
}
r, err = getCgroupMemFile(containerId, base, "memory.max_usage_in_bytes")
r, err = getCgroupMemFile(containerID, base, "memory.max_usage_in_bytes")
if err == nil {
ret.MemMaxUsageInBytes = r
}
r, err = getCgroupMemFile(containerId, base, "memoryLimitInBbytes")
r, err = getCgroupMemFile(containerID, base, "memoryLimitInBbytes")
if err == nil {
ret.MemLimitInBytes = r
}
r, err = getCgroupMemFile(containerId, base, "memoryFailcnt")
r, err = getCgroupMemFile(containerID, base, "memoryFailcnt")
if err == nil {
ret.MemFailCnt = r
}

return ret, nil
}

func CgroupMemDocker(containerId string) (*CgroupMemStat, error) {
return CgroupMem(containerId, common.HostSys("fs/cgroup/memory/docker"))
func CgroupMemDocker(containerID string) (*CgroupMemStat, error) {
return CgroupMem(containerID, common.HostSys("fs/cgroup/memory/docker"))
}

func (m CgroupMemStat) String() string {
Expand All @@ -184,24 +184,23 @@ func (m CgroupMemStat) String() string {
}

// getCgroupFilePath constructs file path to get targetted stats file.
func getCgroupFilePath(containerId, base, target, file string) string {
func getCgroupFilePath(containerID, base, target, file string) string {
if len(base) == 0 {
base = common.HostSys(fmt.Sprintf("fs/cgroup/%s/docker", target))
}
statfile := path.Join(base, containerId, file)
statfile := path.Join(base, containerID, file)

if _, err := os.Stat(statfile); os.IsNotExist(err) {
statfile = path.Join(
common.HostSys(fmt.Sprintf("fs/cgroup/%s/system.slice", target)), "docker-"+containerId+".scope", file)
common.HostSys(fmt.Sprintf("fs/cgroup/%s/system.slice", target)), "docker-"+containerID+".scope", file)
}

return statfile
}

// getCgroupMemFile reads a cgroup file and return the contents as uint64.
func getCgroupMemFile(containerId, base, file string) (uint64, error) {

statfile := getCgroupFilePath(containerId, base, "memory", file)
func getCgroupMemFile(containerID, base, file string) (uint64, error) {
statfile := getCgroupFilePath(containerID, base, "memory", file)
lines, err := common.ReadLines(statfile)
if err != nil {
return 0, err
Expand Down
4 changes: 2 additions & 2 deletions internal/common/binary.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package common

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
Expand All @@ -19,8 +21,6 @@
// high-performance serialization, especially for large data structures,
// should look at more advanced solutions such as the encoding/gob
// package or protocol buffers.
package common

import (
"errors"
"io"
Expand Down
9 changes: 4 additions & 5 deletions internal/common/common.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package common

//
// gopsutil is a port of psutil(http://pythonhosted.org/psutil/).
// This covers these architectures.
// - linux (amd64, arm)
// - freebsd (amd64)
// - windows (amd64)
package common

import (
"bufio"
"errors"
Expand Down Expand Up @@ -59,12 +59,11 @@ func (i FakeInvoke) Command(name string, arg ...string) ([]byte, error) {
}
if PathExists(fpath) {
return ioutil.ReadFile(fpath)
} else {
return exec.Command(name, arg...).Output()
}
return exec.Command(name, arg...).Output()
}

var NotImplementedError = errors.New("not implemented yet")
var ErrNotImplementedError = errors.New("not implemented yet")

// ReadLines reads contents from a file and splits them by new lines.
// A convenience wrapper to ReadLinesOffsetN(filename, 0, -1).
Expand Down
4 changes: 2 additions & 2 deletions load/load_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func Misc() (*MiscStat, error) {
ret := MiscStat{}
for _, l := range lines {
if strings.Contains(l, "R") {
ret.ProcsRunning += 1
ret.ProcsRunning++
} else if strings.Contains(l, "U") {
// uninterruptible sleep == blocked
ret.ProcsBlocked += 1
ret.ProcsBlocked++
}
}

Expand Down
4 changes: 2 additions & 2 deletions load/load_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func Misc() (*MiscStat, error) {
ret := MiscStat{}
for _, l := range lines {
if strings.Contains(l, "R") {
ret.ProcsRunning += 1
ret.ProcsRunning++
} else if strings.Contains(l, "D") {
ret.ProcsBlocked += 1
ret.ProcsBlocked++
}
}

Expand Down
4 changes: 2 additions & 2 deletions load/load_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
func Avg() (*AvgStat, error) {
ret := AvgStat{}

return &ret, common.NotImplementedError
return &ret, common.ErrNotImplementedError
}

func Misc() (*MiscStat, error) {
ret := MiscStat{}

return &ret, common.NotImplementedError
return &ret, common.ErrNotImplementedError
}
7 changes: 6 additions & 1 deletion mem/mem_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
// Return swapinfo
// FreeBSD can have multiple swap devices. but use only first device
func SwapMemory() (*SwapMemoryStat, error) {
out, err := exec.Command("swapinfo").Output()
swapinfo, err := exec.LookPath("swapinfo")
if err != nil {
return nil, err
}

out, err := exec.Command(swapinfo).Output()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions mem/mem_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
)

type MEMORYSTATUSEX struct {
type memoryStatusEx struct {
cbSize uint32
dwMemoryLoad uint32
ullTotalPhys uint64 // in bytes
Expand All @@ -26,7 +26,7 @@ type MEMORYSTATUSEX struct {
}

func VirtualMemory() (*VirtualMemoryStat, error) {
var memInfo MEMORYSTATUSEX
var memInfo memoryStatusEx
memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo)))
if mem == 0 {
Expand Down
6 changes: 5 additions & 1 deletion net/net_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import (
// lo0 16384 ::1/128 ::1 869107 - 169411755 869107 - 169411755 - -
// lo0 16384 127 127.0.0.1 869107 - 169411755 869107 - 169411755 - -
func IOCounters(pernic bool) ([]IOCountersStat, error) {
out, err := exec.Command("/usr/sbin/netstat", "-ibdnW").Output()
netstat, err := exec.LookPath("/usr/bin/netstat")
if err != nil {
return nil, err
}
out, err := exec.Command(netstat, "-ibdnW").Output()
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion net/net_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import (
)

func IOCounters(pernic bool) ([]IOCountersStat, error) {
out, err := exec.Command("/usr/bin/netstat", "-ibdnW").Output()
netstat, err := exec.LookPath("/usr/bin/netstat")
if err != nil {
return nil, err
}
out, err := exec.Command(netstat, "-ibdnW").Output()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion net/net_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) {
case "udp6":
args = append(args, "6udp")
case "unix":
return ret, common.NotImplementedError
return ret, common.ErrNotImplementedError
}

r, err := common.CallLsof(invoke, pid, args...)
Expand Down
6 changes: 3 additions & 3 deletions net/net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

var (
modiphlpapi = syscall.NewLazyDLL("iphlpapi.dll")
procGetExtendedTcpTable = modiphlpapi.NewProc("GetExtendedTcpTable")
procGetExtendedUdpTable = modiphlpapi.NewProc("GetExtendedUdpTable")
procGetExtendedTCPTable = modiphlpapi.NewProc("GetExtendedTcpTable")
procGetExtendedUDPTable = modiphlpapi.NewProc("GetExtendedUdpTable")
)

const (
Expand Down Expand Up @@ -83,7 +83,7 @@ func IOCountersByFile(pernic bool, filename string) ([]IOCountersStat, error) {
func Connections(kind string) ([]ConnectionStat, error) {
var ret []ConnectionStat

return ret, common.NotImplementedError
return ret, common.ErrNotImplementedError
}

// borrowed from src/pkg/net/interface_windows.go
Expand Down
Loading

0 comments on commit 613a8a9

Please sign in to comment.