[BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters

pull/177/head
Shirou WAKAYAMA 9 years ago
parent 70ba28090d
commit ea152ea901

@ -7,7 +7,7 @@ import (
"strings"
)
type CPUTimesStat struct {
type TimesStat struct {
CPU string `json:"cpu"`
User float64 `json:"user"`
System float64 `json:"system"`
@ -22,7 +22,7 @@ type CPUTimesStat struct {
Stolen float64 `json:"stolen"`
}
type CPUInfoStat struct {
type InfoStat struct {
CPU int32 `json:"cpu"`
VendorID string `json:"vendor_id"`
Family string `json:"family"`
@ -37,14 +37,14 @@ type CPUInfoStat struct {
Flags []string `json:"flags"`
}
var lastCPUTimes []CPUTimesStat
var lastPerCPUTimes []CPUTimesStat
var lastCPUTimes []TimesStat
var lastPerCPUTimes []TimesStat
func CPUCounts(logical bool) (int, error) {
func Counts(logical bool) (int, error) {
return runtime.NumCPU(), nil
}
func (c CPUTimesStat) String() string {
func (c TimesStat) String() string {
v := []string{
`"cpu":"` + c.CPU + `"`,
`"user":` + strconv.FormatFloat(c.User, 'f', 1, 64),
@ -64,13 +64,13 @@ func (c CPUTimesStat) String() string {
}
// Total returns the total number of seconds in a CPUTimesStat
func (c CPUTimesStat) Total() float64 {
func (c TimesStat) Total() float64 {
total := c.User + c.System + c.Nice + c.Iowait + c.Irq + c.Softirq + c.Steal +
c.Guest + c.GuestNice + c.Idle + c.Stolen
return total
}
func (c CPUInfoStat) String() string {
func (c InfoStat) String() string {
s, _ := json.Marshal(c)
return string(s)
}

@ -21,7 +21,7 @@ const (
// default value. from time.h
var ClocksPerSec = float64(128)
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
func Times(percpu bool) ([]TimesStat, error) {
if percpu {
return perCPUTimes()
}
@ -30,15 +30,15 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
}
// Returns only one CPUInfoStat on FreeBSD
func CPUInfo() ([]CPUInfoStat, error) {
var ret []CPUInfoStat
func Info() ([]InfoStat, error) {
var ret []InfoStat
out, err := exec.Command("/usr/sbin/sysctl", "machdep.cpu").Output()
if err != nil {
return ret, err
}
c := CPUInfoStat{}
c := InfoStat{}
for _, line := range strings.Split(string(out), "\n") {
values := strings.Fields(line)
if len(values) < 1 {

@ -25,7 +25,7 @@ import (
// these CPU times for darwin is borrowed from influxdb/telegraf.
func perCPUTimes() ([]CPUTimesStat, error) {
func perCPUTimes() ([]TimesStat, error) {
var (
count C.mach_msg_type_number_t
cpuload *C.processor_cpu_load_info_data_t
@ -59,7 +59,7 @@ func perCPUTimes() ([]CPUTimesStat, error) {
bbuf := bytes.NewBuffer(buf)
var ret []CPUTimesStat
var ret []TimesStat
for i := 0; i < int(ncpu); i++ {
err := binary.Read(bbuf, binary.LittleEndian, &cpu_ticks)
@ -67,7 +67,7 @@ func perCPUTimes() ([]CPUTimesStat, error) {
return nil, err
}
c := CPUTimesStat{
c := TimesStat{
CPU: fmt.Sprintf("cpu%d", i),
User: float64(cpu_ticks[C.CPU_STATE_USER]) / ClocksPerSec,
System: float64(cpu_ticks[C.CPU_STATE_SYSTEM]) / ClocksPerSec,
@ -81,7 +81,7 @@ func perCPUTimes() ([]CPUTimesStat, error) {
return ret, nil
}
func allCPUTimes() ([]CPUTimesStat, error) {
func allCPUTimes() ([]TimesStat, error) {
var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT
var cpuload C.host_cpu_load_info_data_t
@ -94,7 +94,7 @@ func allCPUTimes() ([]CPUTimesStat, error) {
return nil, fmt.Errorf("host_statistics error=%d", status)
}
c := CPUTimesStat{
c := TimesStat{
CPU: "cpu-total",
User: float64(cpuload.cpu_ticks[C.CPU_STATE_USER]) / ClocksPerSec,
System: float64(cpuload.cpu_ticks[C.CPU_STATE_SYSTEM]) / ClocksPerSec,
@ -102,6 +102,6 @@ func allCPUTimes() ([]CPUTimesStat, error) {
Idle: float64(cpuload.cpu_ticks[C.CPU_STATE_IDLE]) / ClocksPerSec,
}
return []CPUTimesStat{c}, nil
return []TimesStat{c}, nil
}

@ -5,10 +5,10 @@ package cpu
import "github.com/shirou/gopsutil/internal/common"
func perCPUTimes() ([]CPUTimesStat, error) {
return []CPUTimesStat{}, common.NotImplementedError
func perCPUTimes() ([]TimesStat, error) {
return []TimesStat{}, common.NotImplementedError
}
func allCPUTimes() ([]CPUTimesStat, error) {
return []CPUTimesStat{}, common.NotImplementedError
func allCPUTimes() ([]TimesStat, error) {
return []TimesStat{}, common.NotImplementedError
}

@ -35,14 +35,14 @@ func init() {
}
}
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
var ret []CPUTimesStat
func Times(percpu bool) ([]TimesStat, error) {
var ret []TimesStat
var sysctlCall string
var ncpu int
if percpu {
sysctlCall = "kern.cp_times"
ncpu, _ = CPUCounts(true)
ncpu, _ = Counts(true)
} else {
sysctlCall = "kern.cp_time"
ncpu = 1
@ -76,7 +76,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
return ret, err
}
c := CPUTimesStat{
c := TimesStat{
User: float64(user / ClocksPerSec),
Nice: float64(nice / ClocksPerSec),
System: float64(sys / ClocksPerSec),
@ -96,13 +96,13 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
}
// Returns only one CPUInfoStat on FreeBSD
func CPUInfo() ([]CPUInfoStat, error) {
func Info() ([]InfoStat, error) {
filename := "/var/run/dmesg.boot"
lines, _ := common.ReadLines(filename)
var ret []CPUInfoStat
var ret []InfoStat
c := CPUInfoStat{}
c := InfoStat{}
for _, line := range lines {
if matches := regexp.MustCompile(`CPU:\s+(.+) \(([\d.]+).+\)`).FindStringSubmatch(line); matches != nil {
c.ModelName = matches[1]

@ -25,7 +25,7 @@ func init() {
}
}
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
func Times(percpu bool) ([]TimesStat, error) {
filename := common.HostProc("stat")
var lines = []string{}
if percpu {
@ -43,7 +43,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
lines, _ = common.ReadLinesOffsetN(filename, 0, 1)
}
ret := make([]CPUTimesStat, 0, len(lines))
ret := make([]TimesStat, 0, len(lines))
for _, line := range lines {
ct, err := parseStatLine(line)
@ -60,7 +60,7 @@ func sysCpuPath(cpu int32, relPath string) string {
return common.HostSys(fmt.Sprintf("devices/system/cpu/cpu%d", cpu), relPath)
}
func finishCPUInfo(c *CPUInfoStat) error {
func finishCPUInfo(c *InfoStat) error {
if c.Mhz == 0 {
lines, err := common.ReadLines(sysCpuPath(c.CPU, "cpufreq/cpuinfo_max_freq"))
if err == nil {
@ -87,13 +87,13 @@ func finishCPUInfo(c *CPUInfoStat) error {
// Sockets often come with many physical CPU cores.
// For example a single socket board with two cores each with HT will
// return 4 CPUInfoStat structs on Linux and the "Cores" field set to 1.
func CPUInfo() ([]CPUInfoStat, error) {
func Info() ([]InfoStat, error) {
filename := common.HostProc("cpuinfo")
lines, _ := common.ReadLines(filename)
var ret []CPUInfoStat
var ret []InfoStat
c := CPUInfoStat{CPU: -1, Cores: 1}
c := InfoStat{CPU: -1, Cores: 1}
for _, line := range lines {
fields := strings.Split(line, ":")
if len(fields) < 2 {
@ -111,7 +111,7 @@ func CPUInfo() ([]CPUInfoStat, error) {
}
ret = append(ret, c)
}
c = CPUInfoStat{Cores: 1}
c = InfoStat{Cores: 1}
t, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return ret, err
@ -163,7 +163,7 @@ func CPUInfo() ([]CPUInfoStat, error) {
return ret, nil
}
func parseStatLine(line string) (*CPUTimesStat, error) {
func parseStatLine(line string) (*TimesStat, error) {
fields := strings.Fields(line)
if strings.HasPrefix(fields[0], "cpu") == false {
@ -204,7 +204,7 @@ func parseStatLine(line string) (*CPUTimesStat, error) {
return nil, err
}
ct := &CPUTimesStat{
ct := &TimesStat{
CPU: cpu,
User: float64(user) / cpu_tick,
Nice: float64(nice) / cpu_tick,

@ -9,14 +9,14 @@ import (
)
func TestCpu_times(t *testing.T) {
v, err := CPUTimes(false)
v, err := Times(false)
if err != nil {
t.Errorf("error %v", err)
}
if len(v) == 0 {
t.Error("could not get CPUs ", err)
}
empty := CPUTimesStat{}
empty := TimesStat{}
for _, vv := range v {
if vv == empty {
t.Errorf("could not get CPU User: %v", vv)
@ -25,7 +25,7 @@ func TestCpu_times(t *testing.T) {
}
func TestCpu_counts(t *testing.T) {
v, err := CPUCounts(true)
v, err := Counts(true)
if err != nil {
t.Errorf("error %v", err)
}
@ -35,7 +35,7 @@ func TestCpu_counts(t *testing.T) {
}
func TestCPUTimeStat_String(t *testing.T) {
v := CPUTimesStat{
v := TimesStat{
CPU: "cpu0",
User: 100.1,
System: 200.1,
@ -48,7 +48,7 @@ func TestCPUTimeStat_String(t *testing.T) {
}
func TestCpuInfo(t *testing.T) {
v, err := CPUInfo()
v, err := Info()
if err != nil {
t.Errorf("error %v", err)
}
@ -68,7 +68,7 @@ func testCPUPercent(t *testing.T, percpu bool) {
if runtime.GOOS != "windows" {
testCount = 100
v, err := CPUPercent(time.Millisecond, percpu)
v, err := Percent(time.Millisecond, percpu)
if err != nil {
t.Errorf("error %v", err)
}
@ -81,7 +81,7 @@ func testCPUPercent(t *testing.T, percpu bool) {
}
for i := 0; i < testCount; i++ {
duration := time.Duration(10) * time.Microsecond
v, err := CPUPercent(duration, percpu)
v, err := Percent(duration, percpu)
if err != nil {
t.Errorf("error %v", err)
}

@ -7,14 +7,14 @@ import (
"time"
)
func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
getAllBusy := func(t CPUTimesStat) (float64, float64) {
func Percent(interval time.Duration, percpu bool) ([]float64, error) {
getAllBusy := func(t TimesStat) (float64, float64) {
busy := t.User + t.System + t.Nice + t.Iowait + t.Irq +
t.Softirq + t.Steal + t.Guest + t.GuestNice + t.Stolen
return busy + t.Idle, busy
}
calculate := func(t1, t2 CPUTimesStat) float64 {
calculate := func(t1, t2 TimesStat) float64 {
t1All, t1Busy := getAllBusy(t1)
t2All, t2Busy := getAllBusy(t2)
@ -28,7 +28,7 @@ func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
}
// Get CPU usage at the start of the interval.
cpuTimes1, err := CPUTimes(percpu)
cpuTimes1, err := Times(percpu)
if err != nil {
return nil, err
}
@ -38,7 +38,7 @@ func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
}
// And at the end of the interval.
cpuTimes2, err := CPUTimes(percpu)
cpuTimes2, err := Times(percpu)
if err != nil {
return nil, err
}

@ -25,8 +25,8 @@ type Win32_Processor struct {
}
// TODO: Get percpu
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
var ret []CPUTimesStat
func Times(percpu bool) ([]TimesStat, error) {
var ret []TimesStat
var lpIdleTime common.FILETIME
var lpKernelTime common.FILETIME
@ -46,7 +46,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
kernel := ((HIT * float64(lpKernelTime.DwHighDateTime)) + (LOT * float64(lpKernelTime.DwLowDateTime)))
system := (kernel - idle)
ret = append(ret, CPUTimesStat{
ret = append(ret, TimesStat{
Idle: float64(idle),
User: float64(user),
System: float64(system),
@ -54,8 +54,8 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
return ret, nil
}
func CPUInfo() ([]CPUInfoStat, error) {
var ret []CPUInfoStat
func Info() ([]InfoStat, error) {
var ret []InfoStat
var dst []Win32_Processor
q := wmi.CreateQuery(&dst, "")
err := wmi.Query(q, &dst)
@ -70,7 +70,7 @@ func CPUInfo() ([]CPUInfoStat, error) {
procID = *l.ProcessorId
}
cpu := CPUInfoStat{
cpu := InfoStat{
CPU: int32(i),
Family: fmt.Sprintf("%d", l.Family),
VendorID: l.Manufacturer,
@ -86,7 +86,7 @@ func CPUInfo() ([]CPUInfoStat, error) {
return ret, nil
}
func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
func Percent(interval time.Duration, percpu bool) ([]float64, error) {
var ret []float64
var dst []Win32_Processor
q := wmi.CreateQuery(&dst, "")

@ -4,7 +4,7 @@ import (
"encoding/json"
)
type DiskUsageStat struct {
type UsageStat struct {
Path string `json:"path"`
Fstype string `json:"fstype"`
Total uint64 `json:"total"`
@ -17,14 +17,14 @@ type DiskUsageStat struct {
InodesUsedPercent float64 `json:"inodes_used_percent"`
}
type DiskPartitionStat struct {
type PartitionStat struct {
Device string `json:"device"`
Mountpoint string `json:"mountpoint"`
Fstype string `json:"fstype"`
Opts string `json:"opts"`
}
type DiskIOCountersStat struct {
type IOCountersStat struct {
ReadCount uint64 `json:"read_count"`
WriteCount uint64 `json:"write_count"`
ReadBytes uint64 `json:"read_bytes"`
@ -36,17 +36,17 @@ type DiskIOCountersStat struct {
SerialNumber string `json:"serial_number"`
}
func (d DiskUsageStat) String() string {
func (d UsageStat) String() string {
s, _ := json.Marshal(d)
return string(s)
}
func (d DiskPartitionStat) String() string {
func (d PartitionStat) String() string {
s, _ := json.Marshal(d)
return string(s)
}
func (d DiskIOCountersStat) String() string {
func (d IOCountersStat) String() string {
s, _ := json.Marshal(d)
return string(s)
}

@ -9,8 +9,8 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
var ret []DiskPartitionStat
func Partitions(all bool) ([]PartitionStat, error) {
var ret []PartitionStat
count, err := Getfsstat(nil, MntWait)
if err != nil {
@ -68,7 +68,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
if stat.Flags&MntNFS4ACLs != 0 {
opts += ",nfs4acls"
}
d := DiskPartitionStat{
d := PartitionStat{
Device: common.IntToString(stat.Mntfromname[:]),
Mountpoint: common.IntToString(stat.Mntonname[:]),
Fstype: common.IntToString(stat.Fstypename[:]),
@ -80,7 +80,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
return ret, nil
}
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
func IOCounters() (map[string]IOCountersStat, error) {
return nil, common.NotImplementedError
}

@ -12,8 +12,8 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
var ret []DiskPartitionStat
func Partitions(all bool) ([]PartitionStat, error) {
var ret []PartitionStat
// get length
count, err := syscall.Getfsstat(nil, MNT_WAIT)
@ -75,7 +75,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
opts += ",nfs4acls"
}
d := DiskPartitionStat{
d := PartitionStat{
Device: common.IntToString(stat.Mntfromname[:]),
Mountpoint: common.IntToString(stat.Mntonname[:]),
Fstype: common.IntToString(stat.Fstypename[:]),
@ -87,10 +87,10 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
return ret, nil
}
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
func IOCounters() (map[string]IOCountersStat, error) {
// statinfo->devinfo->devstat
// /usr/include/devinfo.h
ret := make(map[string]DiskIOCountersStat)
ret := make(map[string]IOCountersStat)
r, err := syscall.Sysctl("kern.devstat.all")
if err != nil {
@ -114,7 +114,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
un := strconv.Itoa(int(d.Unit_number))
name := common.IntToString(d.Device_name[:]) + un
ds := DiskIOCountersStat{
ds := IOCountersStat{
ReadCount: d.Operations[DEVSTAT_READ],
WriteCount: d.Operations[DEVSTAT_WRITE],
ReadBytes: d.Bytes[DEVSTAT_READ],

@ -95,7 +95,7 @@ type Devstat struct {
Flags uint32
Device_type uint32
Priority uint32
Id *byte
ID *byte
Sequence1 uint32
}
type Bintime struct {

@ -97,7 +97,7 @@ type Devstat struct {
Device_type uint32
Priority uint32
Pad_cgo_1 [4]byte
Id *byte
ID *byte
Sequence1 uint32
Pad_cgo_2 [4]byte
}

@ -213,18 +213,18 @@ var fsTypeMap = map[int64]string{
// Get disk partitions.
// should use setmntent(3) but this implement use /etc/mtab file
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
func Partitions(all bool) ([]PartitionStat, error) {
filename := common.HostEtc("mtab")
lines, err := common.ReadLines(filename)
if err != nil {
return nil, err
}
ret := make([]DiskPartitionStat, 0, len(lines))
ret := make([]PartitionStat, 0, len(lines))
for _, line := range lines {
fields := strings.Fields(line)
d := DiskPartitionStat{
d := PartitionStat{
Device: fields[0],
Mountpoint: fields[1],
Fstype: fields[2],
@ -236,14 +236,14 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
return ret, nil
}
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
func IOCounters() (map[string]IOCountersStat, error) {
filename := common.HostProc("diskstats")
lines, err := common.ReadLines(filename)
if err != nil {
return nil, err
}
ret := make(map[string]DiskIOCountersStat, 0)
empty := DiskIOCountersStat{}
ret := make(map[string]IOCountersStat, 0)
empty := IOCountersStat{}
for _, line := range lines {
fields := strings.Fields(line)
@ -276,7 +276,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
if err != nil {
return ret, err
}
d := DiskIOCountersStat{
d := IOCountersStat{
ReadBytes: rbytes * SectorSize,
WriteBytes: wbytes * SectorSize,
ReadCount: reads,

@ -11,7 +11,7 @@ func TestDisk_usage(t *testing.T) {
if runtime.GOOS == "windows" {
path = "C:"
}
v, err := DiskUsage(path)
v, err := Usage(path)
if err != nil {
t.Errorf("error %v", err)
}
@ -21,11 +21,11 @@ func TestDisk_usage(t *testing.T) {
}
func TestDisk_partitions(t *testing.T) {
ret, err := DiskPartitions(false)
ret, err := Partitions(false)
if err != nil || len(ret) == 0 {
t.Errorf("error %v", err)
}
empty := DiskPartitionStat{}
empty := PartitionStat{}
for _, disk := range ret {
if disk == empty {
t.Errorf("Could not get device info %v", disk)
@ -34,14 +34,14 @@ func TestDisk_partitions(t *testing.T) {
}
func TestDisk_io_counters(t *testing.T) {
ret, err := DiskIOCounters()
ret, err := IOCounters()
if err != nil {
t.Errorf("error %v", err)
}
if len(ret) == 0 {
t.Errorf("ret is empty, %v", ret)
}
empty := DiskIOCountersStat{}
empty := IOCountersStat{}
for part, io := range ret {
if io == empty {
t.Errorf("io_counter error %v, %v", part, io)
@ -50,7 +50,7 @@ func TestDisk_io_counters(t *testing.T) {
}
func TestDiskUsageStat_String(t *testing.T) {
v := DiskUsageStat{
v := UsageStat{
Path: "/",
Total: 1000,
Free: 2000,
@ -69,7 +69,7 @@ func TestDiskUsageStat_String(t *testing.T) {
}
func TestDiskPartitionStat_String(t *testing.T) {
v := DiskPartitionStat{
v := PartitionStat{
Device: "sd01",
Mountpoint: "/",
Fstype: "ext4",
@ -82,7 +82,7 @@ func TestDiskPartitionStat_String(t *testing.T) {
}
func TestDiskIOCountersStat_String(t *testing.T) {
v := DiskIOCountersStat{
v := IOCountersStat{
Name: "sd01",
ReadCount: 100,
WriteCount: 200,

@ -4,7 +4,7 @@ package disk
import "syscall"
func DiskUsage(path string) (*DiskUsageStat, error) {
func Usage(path string) (*UsageStat, error) {
stat := syscall.Statfs_t{}
err := syscall.Statfs(path, &stat)
if err != nil {
@ -12,7 +12,7 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
}
bsize := stat.Bsize
ret := &DiskUsageStat{
ret := &UsageStat{
Path: path,
Fstype: getFsType(stat),
Total: (uint64(stat.Blocks) * uint64(bsize)),

@ -36,8 +36,8 @@ type Win32_PerfFormattedData struct {
const WaitMSec = 500
func DiskUsage(path string) (*DiskUsageStat, error) {
ret := &DiskUsageStat{}
func Usage(path string) (*UsageStat, error) {
ret := &UsageStat{}
lpFreeBytesAvailable := int64(0)
lpTotalNumberOfBytes := int64(0)
@ -50,7 +50,7 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
if diskret == 0 {
return nil, err
}
ret = &DiskUsageStat{
ret = &UsageStat{
Path: path,
Total: uint64(lpTotalNumberOfBytes),
Free: uint64(lpTotalNumberOfFreeBytes),
@ -64,8 +64,8 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
return ret, nil
}
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
var ret []DiskPartitionStat
func Partitions(all bool) ([]PartitionStat, error) {
var ret []PartitionStat
lpBuffer := make([]byte, 254)
diskret, _, err := procGetLogicalDriveStringsW.Call(
uintptr(len(lpBuffer)),
@ -116,7 +116,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
opts += ".compress"
}
d := DiskPartitionStat{
d := PartitionStat{
Mountpoint: path,
Device: path,
Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)),
@ -129,8 +129,8 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
return ret, nil
}
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
ret := make(map[string]DiskIOCountersStat, 0)
func IOCounters() (map[string]IOCountersStat, error) {
ret := make(map[string]IOCountersStat, 0)
var dst []Win32_PerfFormattedData
err := wmi.Query("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk ", &dst)
@ -141,7 +141,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
if len(d.Name) > 3 { // not get _Total or Harddrive
continue
}
ret[d.Name] = DiskIOCountersStat{
ret[d.Name] = IOCountersStat{
Name: d.Name,
ReadCount: uint64(d.AvgDiskReadQueueLength),
WriteCount: d.AvgDiskWriteQueueLength,

@ -44,7 +44,7 @@ func GetDockerIDList() ([]string, error) {
// 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.CPUTimesStat, error) {
func CgroupCPU(containerId string, base string) (*cpu.TimesStat, error) {
statfile := getCgroupFilePath(containerId, base, "cpuacct", "cpuacct.stat")
lines, err := common.ReadLines(statfile)
if err != nil {
@ -54,7 +54,7 @@ func CgroupCPU(containerId string, base string) (*cpu.CPUTimesStat, error) {
if len(containerId) == 0 {
containerId = "all"
}
ret := &cpu.CPUTimesStat{CPU: containerId}
ret := &cpu.TimesStat{CPU: containerId}
for _, line := range lines {
fields := strings.Split(line, " ")
if fields[0] == "user" {
@ -74,7 +74,7 @@ func CgroupCPU(containerId string, base string) (*cpu.CPUTimesStat, error) {
return ret, nil
}
func CgroupCPUDocker(containerid string) (*cpu.CPUTimesStat, error) {
func CgroupCPUDocker(containerid string) (*cpu.TimesStat, error) {
return CgroupCPU(containerid, common.HostSys("fs/cgroup/cpuacct/docker"))
}

@ -19,11 +19,11 @@ func GetDockerIDList() ([]string, error) {
// 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.CPUTimesStat, error) {
func CgroupCPU(containerid string, base string) (*cpu.TimesStat, error) {
return nil, ErrCgroupNotAvailable
}
func CgroupCPUDocker(containerid string) (*cpu.CPUTimesStat, error) {
func CgroupCPUDocker(containerid string) (*cpu.TimesStat, error) {
return CgroupCPU(containerid, common.HostSys("fs/cgroup/cpuacct/docker"))
}

@ -6,7 +6,7 @@ import (
// A HostInfoStat describes the host status.
// This is not in the psutil but it useful.
type HostInfoStat struct {
type InfoStat struct {
Hostname string `json:"hostname"`
Uptime uint64 `json:"uptime"`
BootTime uint64 `json:"boot_time"`
@ -27,7 +27,7 @@ type UserStat struct {
Started int `json:"started"`
}
func (h HostInfoStat) String() string {
func (h InfoStat) String() string {
s, _ := json.Marshal(h)
return string(s)
}

@ -20,8 +20,8 @@ import (
// from utmpx.h
const USER_PROCESS = 7
func HostInfo() (*HostInfoStat, error) {
ret := &HostInfoStat{
func Info() (*InfoStat, error) {
ret := &InfoStat{
OS: runtime.GOOS,
PlatformFamily: "darwin",
}
@ -31,13 +31,13 @@ func HostInfo() (*HostInfoStat, error) {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
platform, family, version, err := PlatformInformation()
if err == nil {
ret.Platform = platform
ret.PlatformFamily = family
ret.PlatformVersion = version
}
system, role, err := GetVirtualization()
system, role, err := Virtualization()
if err == nil {
ret.VirtualizationSystem = system
ret.VirtualizationRole = role
@ -122,7 +122,7 @@ func Users() ([]UserStat, error) {
}
func GetPlatformInformation() (string, string, string, error) {
func PlatformInformation() (string, string, string, error) {
platform := ""
family := ""
version := ""
@ -140,7 +140,7 @@ func GetPlatformInformation() (string, string, string, error) {
return platform, family, version, nil
}
func GetVirtualization() (string, string, error) {
func Virtualization() (string, string, error) {
system := ""
role := ""

@ -5,7 +5,7 @@ package host
type Utmpx struct {
User [256]int8
Id [4]int8
ID [4]int8
Line [32]int8
Pid int32
Type int16

@ -23,8 +23,8 @@ const (
UTHostSize = 16
)
func HostInfo() (*HostInfoStat, error) {
ret := &HostInfoStat{
func Info() (*InfoStat, error) {
ret := &InfoStat{
OS: runtime.GOOS,
PlatformFamily: "freebsd",
}
@ -34,13 +34,13 @@ func HostInfo() (*HostInfoStat, error) {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
platform, family, version, err := PlatformInformation()
if err == nil {
ret.Platform = platform
ret.PlatformFamily = family
ret.PlatformVersion = version
}
system, role, err := GetVirtualization()
system, role, err := Virtualization()
if err == nil {
ret.VirtualizationSystem = system
ret.VirtualizationRole = role
@ -129,7 +129,7 @@ func Users() ([]UserStat, error) {
}
func GetPlatformInformation() (string, string, string, error) {
func PlatformInformation() (string, string, string, error) {
platform := ""
family := ""
version := ""
@ -147,7 +147,7 @@ func GetPlatformInformation() (string, string, string, error) {
return platform, family, version, nil
}
func GetVirtualization() (string, string, error) {
func Virtualization() (string, string, error) {
system := ""
role := ""

@ -27,7 +27,7 @@ type Utmp struct {
type Utmpx struct {
Type int16
Tv Timeval
Id [8]int8
ID [8]int8
Pid int32
User [32]int8
Line [16]int8

@ -29,8 +29,8 @@ type LSB struct {
// from utmp.h
const USER_PROCESS = 7
func HostInfo() (*HostInfoStat, error) {
ret := &HostInfoStat{
func Info() (*InfoStat, error) {
ret := &InfoStat{
OS: runtime.GOOS,
}
@ -39,13 +39,13 @@ func HostInfo() (*HostInfoStat, error) {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
platform, family, version, err := PlatformInformation()
if err == nil {
ret.Platform = platform
ret.PlatformFamily = family
ret.PlatformVersion = version
}
system, role, err := GetVirtualization()
system, role, err := Virtualization()
if err == nil {
ret.VirtualizationSystem = system
ret.VirtualizationRole = role
@ -189,7 +189,7 @@ func getLSB() (*LSB, error) {
return ret, nil
}
func GetPlatformInformation() (platform string, family string, version string, err error) {
func PlatformInformation() (platform string, family string, version string, err error) {
lsb, err := getLSB()
if err != nil {
@ -338,7 +338,7 @@ func getSusePlatform(contents []string) string {
return "suse"
}
func GetVirtualization() (string, string, error) {
func Virtualization() (string, string, error) {
var system string
var role string

@ -25,7 +25,7 @@ type utmp struct {
Pad_cgo_0 [2]byte
Pid int32
Line [32]int8
Id [4]int8
ID [4]int8
User [32]int8
Host [256]int8
Exit exit_status

@ -23,7 +23,7 @@ type utmp struct {
Pad_cgo_0 [2]byte
Pid int32
Line [32]int8
Id [4]int8
ID [4]int8
User [32]int8
Host [256]int8
Exit exit_status

@ -23,7 +23,7 @@ type utmp struct {
Pad_cgo_0 [2]byte
Pid int32
Line [32]int8
Id [4]int8
ID [4]int8
User [32]int8
Host [256]int8
Exit exit_status

@ -6,11 +6,11 @@ import (
)
func TestHostInfo(t *testing.T) {
v, err := HostInfo()
v, err := Info()
if err != nil {
t.Errorf("error %v", err)
}
empty := &HostInfoStat{}
empty := &InfoStat{}
if v == empty {
t.Errorf("Could not get hostinfo %v", v)
}
@ -40,7 +40,7 @@ func TestUsers(t *testing.T) {
}
func TestHostInfoStat_String(t *testing.T) {
v := HostInfoStat{
v := InfoStat{
Hostname: "test",
Uptime: 3000,
Procs: 100,

@ -28,8 +28,8 @@ type Win32_OperatingSystem struct {
LastBootUpTime time.Time
}
func HostInfo() (*HostInfoStat, error) {
ret := &HostInfoStat{
func Info() (*InfoStat, error) {
ret := &InfoStat{
OS: runtime.GOOS,
}
@ -38,7 +38,7 @@ func HostInfo() (*HostInfoStat, error) {
ret.Hostname = hostname
}
platform, family, version, err := GetPlatformInformation()
platform, family, version, err := PlatformInformation()
if err == nil {
ret.Platform = platform
ret.PlatformFamily = family
@ -100,7 +100,7 @@ func Uptime() (uint64, error) {
return uptime(boot), nil
}
func GetPlatformInformation() (platform string, family string, version string, err error) {
func PlatformInformation() (platform string, family string, version string, err error) {
if osInfo == nil {
_, err = GetOSInfo()
if err != nil {

@ -12,13 +12,13 @@ func init() {
invoke = common.Invoke{}
}
type LoadAvgStat struct {
type AvgStat struct {
Load1 float64 `json:"load1"`
Load5 float64 `json:"load5"`
Load15 float64 `json:"load15"`
}
func (l LoadAvgStat) String() string {
func (l AvgStat) String() string {
s, _ := json.Marshal(l)
return string(s)
}

@ -10,7 +10,7 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
func LoadAvg() (*LoadAvgStat, error) {
func Avg() (*AvgStat, error) {
values, err := common.DoSysctrl("vm.loadavg")
if err != nil {
return nil, err
@ -29,7 +29,7 @@ func LoadAvg() (*LoadAvgStat, error) {
return nil, err
}
ret := &LoadAvgStat{
ret := &AvgStat{
Load1: float64(load1),
Load5: float64(load5),
Load15: float64(load15),
@ -38,7 +38,6 @@ func LoadAvg() (*LoadAvgStat, error) {
return ret, nil
}
// Misc returnes miscellaneous host-wide statistics.
// darwin use ps command to get process running/blocked count.
// Almost same as FreeBSD implementation, but state is different.

@ -10,7 +10,7 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
func LoadAvg() (*LoadAvgStat, error) {
func Avg() (*AvgStat, error) {
values, err := common.DoSysctrl("vm.loadavg")
if err != nil {
return nil, err
@ -29,7 +29,7 @@ func LoadAvg() (*LoadAvgStat, error) {
return nil, err
}
ret := &LoadAvgStat{
ret := &AvgStat{
Load1: float64(load1),
Load5: float64(load5),
Load15: float64(load15),

@ -10,7 +10,7 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
func LoadAvg() (*LoadAvgStat, error) {
func Avg() (*AvgStat, error) {
filename := common.HostProc("loadavg")
line, err := ioutil.ReadFile(filename)
if err != nil {
@ -32,7 +32,7 @@ func LoadAvg() (*LoadAvgStat, error) {
return nil, err
}
ret := &LoadAvgStat{
ret := &AvgStat{
Load1: load1,
Load5: load5,
Load15: load15,
@ -41,7 +41,6 @@ func LoadAvg() (*LoadAvgStat, error) {
return ret, nil
}
// Misc returnes miscellaneous host-wide statistics.
// Note: the name should be changed near future.
func Misc() (*MiscStat, error) {

@ -6,19 +6,19 @@ import (
)
func TestLoad(t *testing.T) {
v, err := LoadAvg()
v, err := Avg()
if err != nil {
t.Errorf("error %v", err)
}
empty := &LoadAvgStat{}
empty := &AvgStat{}
if v == empty {
t.Errorf("error load: %v", v)
}
}
func TestLoadAvgStat_String(t *testing.T) {
v := LoadAvgStat{
v := AvgStat{
Load1: 10.1,
Load5: 20.1,
Load15: 30.1,

@ -6,8 +6,8 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
func LoadAvg() (*LoadAvgStat, error) {
ret := LoadAvgStat{}
func Avg() (*AvgStat, error) {
ret := AvgStat{}
return &ret, common.NotImplementedError
}

@ -17,7 +17,7 @@ func init() {
invoke = common.Invoke{}
}
type NetIOCountersStat struct {
type IOCountersStat struct {
Name string `json:"name"` // interface name
BytesSent uint64 `json:"bytes_sent"` // number of bytes sent
BytesRecv uint64 `json:"bytes_recv"` // number of bytes received
@ -35,7 +35,7 @@ type Addr struct {
Port uint32 `json:"port"`
}
type NetConnectionStat struct {
type ConnectionStat struct {
Fd uint32 `json:"fd"`
Family uint32 `json:"family"`
Type uint32 `json:"type"`
@ -46,25 +46,25 @@ type NetConnectionStat struct {
}
// System wide stats about different network protocols
type NetProtoCountersStat struct {
type ProtoCountersStat struct {
Protocol string `json:"protocol"`
Stats map[string]int64 `json:"stats"`
}
// NetInterfaceAddr is designed for represent interface addresses
type NetInterfaceAddr struct {
type InterfaceAddr struct {
Addr string `json:"addr"`
}
type NetInterfaceStat struct {
MTU int `json:"mtu"` // maximum transmission unit
Name string `json:"name"` // e.g., "en0", "lo0", "eth0.100"
HardwareAddr string `json:"hardwareaddr"` // IEEE MAC-48, EUI-48 and EUI-64 form
Flags []string `json:"flags"` // e.g., FlagUp, FlagLoopback, FlagMulticast
Addrs []NetInterfaceAddr `json:"addrs"`
type InterfaceStat struct {
MTU int `json:"mtu"` // maximum transmission unit
Name string `json:"name"` // e.g., "en0", "lo0", "eth0.100"
HardwareAddr string `json:"hardwareaddr"` // IEEE MAC-48, EUI-48 and EUI-64 form
Flags []string `json:"flags"` // e.g., FlagUp, FlagLoopback, FlagMulticast
Addrs []InterfaceAddr `json:"addrs"`
}
type NetFilterStat struct {
type FilterStat struct {
ConnTrackCount int64 `json:"conntrack_count"`
ConnTrackMax int64 `json:"conntrack_max"`
}
@ -76,17 +76,17 @@ var constMap = map[string]int{
"IPv6": syscall.AF_INET6,
}
func (n NetIOCountersStat) String() string {
func (n IOCountersStat) String() string {
s, _ := json.Marshal(n)
return string(s)
}
func (n NetConnectionStat) String() string {
func (n ConnectionStat) String() string {
s, _ := json.Marshal(n)
return string(s)
}
func (n NetProtoCountersStat) String() string {
func (n ProtoCountersStat) String() string {
s, _ := json.Marshal(n)
return string(s)
}
@ -96,22 +96,22 @@ func (a Addr) String() string {
return string(s)
}
func (n NetInterfaceStat) String() string {
func (n InterfaceStat) String() string {
s, _ := json.Marshal(n)
return string(s)
}
func (n NetInterfaceAddr) String() string {
func (n InterfaceAddr) String() string {
s, _ := json.Marshal(n)
return string(s)
}
func NetInterfaces() ([]NetInterfaceStat, error) {
func Interfaces() ([]InterfaceStat, error) {
is, err := net.Interfaces()
if err != nil {
return nil, err
}
ret := make([]NetInterfaceStat, 0, len(is))
ret := make([]InterfaceStat, 0, len(is))
for _, ifi := range is {
var flags []string
@ -131,7 +131,7 @@ func NetInterfaces() ([]NetInterfaceStat, error) {
flags = append(flags, "multicast")
}
r := NetInterfaceStat{
r := InterfaceStat{
Name: ifi.Name,
MTU: ifi.MTU,
HardwareAddr: ifi.HardwareAddr.String(),
@ -139,9 +139,9 @@ func NetInterfaces() ([]NetInterfaceStat, error) {
}
addrs, err := ifi.Addrs()
if err == nil {
r.Addrs = make([]NetInterfaceAddr, 0, len(addrs))
r.Addrs = make([]InterfaceAddr, 0, len(addrs))
for _, addr := range addrs {
r.Addrs = append(r.Addrs, NetInterfaceAddr{
r.Addrs = append(r.Addrs, InterfaceAddr{
Addr: addr.String(),
})
}
@ -153,8 +153,8 @@ func NetInterfaces() ([]NetInterfaceStat, error) {
return ret, nil
}
func getNetIOCountersAll(n []NetIOCountersStat) ([]NetIOCountersStat, error) {
r := NetIOCountersStat{
func getIOCountersAll(n []IOCountersStat) ([]IOCountersStat, error) {
r := IOCountersStat{
Name: "all",
}
for _, nic := range n {
@ -168,38 +168,38 @@ func getNetIOCountersAll(n []NetIOCountersStat) ([]NetIOCountersStat, error) {
r.Dropout += nic.Dropout
}
return []NetIOCountersStat{r}, nil
return []IOCountersStat{r}, nil
}
func parseNetLine(line string) (NetConnectionStat, error) {
func parseNetLine(line string) (ConnectionStat, error) {
f := strings.Fields(line)
if len(f) < 9 {
return NetConnectionStat{}, fmt.Errorf("wrong line,%s", line)
return ConnectionStat{}, fmt.Errorf("wrong line,%s", line)
}
pid, err := strconv.Atoi(f[1])
if err != nil {
return NetConnectionStat{}, err
return ConnectionStat{}, err
}
fd, err := strconv.Atoi(strings.Trim(f[3], "u"))
if err != nil {
return NetConnectionStat{}, fmt.Errorf("unknown fd, %s", f[3])
return ConnectionStat{}, fmt.Errorf("unknown fd, %s", f[3])
}
netFamily, ok := constMap[f[4]]
if !ok {
return NetConnectionStat{}, fmt.Errorf("unknown family, %s", f[4])
return ConnectionStat{}, fmt.Errorf("unknown family, %s", f[4])
}
netType, ok := constMap[f[7]]
if !ok {
return NetConnectionStat{}, fmt.Errorf("unknown type, %s", f[7])
return ConnectionStat{}, fmt.Errorf("unknown type, %s", f[7])
}
laddr, raddr, err := parseNetAddr(f[8])
if err != nil {
return NetConnectionStat{}, fmt.Errorf("failed to parse netaddr, %s", f[8])
return ConnectionStat{}, fmt.Errorf("failed to parse netaddr, %s", f[8])
}
n := NetConnectionStat{
n := ConnectionStat{
Fd: uint32(fd),
Family: uint32(netFamily),
Type: uint32(netType),

@ -16,14 +16,14 @@ import (
// lo0 16384 <Link#1> 869107 0 169411755 869107 0 169411755 0 0
// lo0 16384 ::1/128 ::1 869107 - 169411755 869107 - 169411755 - -
// lo0 16384 127 127.0.0.1 869107 - 169411755 869107 - 169411755 - -
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
func IOCounters(pernic bool) ([]IOCountersStat, error) {
out, err := exec.Command("/usr/sbin/netstat", "-ibdnW").Output()
if err != nil {
return nil, err
}
lines := strings.Split(string(out), "\n")
ret := make([]NetIOCountersStat, 0, len(lines)-1)
ret := make([]IOCountersStat, 0, len(lines)-1)
exists := make([]string, 0, len(ret))
for _, line := range lines {
@ -70,7 +70,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
parsed = append(parsed, t)
}
n := NetIOCountersStat{
n := IOCountersStat{
Name: values[0],
PacketsRecv: parsed[0],
Errin: parsed[1],
@ -86,18 +86,18 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
}
if pernic == false {
return getNetIOCountersAll(ret)
return getIOCountersAll(ret)
}
return ret, nil
}
// NetIOCountersByFile is an method which is added just a compatibility for linux.
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
return NetIOCounters(pernic)
func IOCountersByFile(pernic bool, filename string) ([]IOCountersStat, error) {
return IOCounters(pernic)
}
func NetFilterCounters() ([]NetFilterStat, error) {
func FilterCounters() ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for darwin")
}
@ -105,6 +105,6 @@ func NetFilterCounters() ([]NetFilterStat, error) {
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.
// Not Implemented for Darwin
func NetProtoCounters(protocols []string) ([]NetProtoCountersStat, error) {
func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for darwin")
}

@ -11,14 +11,14 @@ import (
"github.com/shirou/gopsutil/internal/common"
)
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
func IOCounters(pernic bool) ([]IOCountersStat, error) {
out, err := exec.Command("/usr/bin/netstat", "-ibdnW").Output()
if err != nil {
return nil, err
}
lines := strings.Split(string(out), "\n")
ret := make([]NetIOCountersStat, 0, len(lines)-1)
ret := make([]IOCountersStat, 0, len(lines)-1)
exists := make([]string, 0, len(ret))
for _, line := range lines {
@ -65,7 +65,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
parsed = append(parsed, t)
}
n := NetIOCountersStat{
n := IOCountersStat{
Name: values[0],
PacketsRecv: parsed[0],
Errin: parsed[1],
@ -80,18 +80,18 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
}
if pernic == false {
return getNetIOCountersAll(ret)
return getIOCountersAll(ret)
}
return ret, nil
}
// NetIOCountersByFile is an method which is added just a compatibility for linux.
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
return NetIOCounters(pernic)
func IOCountersByFile(pernic bool, filename string) ([]IOCountersStat, error) {
return IOCounters(pernic)
}
func NetFilterCounters() ([]NetFilterStat, error) {
func FilterCounters() ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for freebsd")
}
@ -99,6 +99,6 @@ func NetFilterCounters() ([]NetFilterStat, error) {
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.
// Not Implemented for FreeBSD
func NetProtoCounters(protocols []string) ([]NetProtoCountersStat, error) {
func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for freebsd")
}

@ -21,12 +21,12 @@ import (
// return only sum of all information (which name is 'all'). If true,
// every network interface installed on the system is returned
// separately.
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
func IOCounters(pernic bool) ([]IOCountersStat, error) {
filename := common.HostProc("net/dev")
return NetIOCountersByFile(pernic, filename)
return IOCountersByFile(pernic, filename)
}
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
func IOCountersByFile(pernic bool, filename string) ([]IOCountersStat, error) {
lines, err := common.ReadLines(filename)
if err != nil {
return nil, err
@ -34,7 +34,7 @@ func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, err
statlen := len(lines) - 1
ret := make([]NetIOCountersStat, 0, statlen)
ret := make([]IOCountersStat, 0, statlen)
for _, line := range lines[2:] {
parts := strings.SplitN(line, ":", 2)
@ -80,7 +80,7 @@ func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, err
return ret, err
}
nic := NetIOCountersStat{
nic := IOCountersStat{
Name: interfaceName,
BytesRecv: bytesRecv,
PacketsRecv: packetsRecv,
@ -95,7 +95,7 @@ func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, err
}
if pernic == false {
return getNetIOCountersAll(ret)
return getIOCountersAll(ret)
}
return ret, nil
@ -115,12 +115,12 @@ var netProtocols = []string{
// just the protocols in the list are returned.
// Available protocols:
// ip,icmp,icmpmsg,tcp,udp,udplite
func NetProtoCounters(protocols []string) ([]NetProtoCountersStat, error) {
func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
if len(protocols) == 0 {
protocols = netProtocols
}
stats := make([]NetProtoCountersStat, 0, len(protocols))
stats := make([]ProtoCountersStat, 0, len(protocols))
protos := make(map[string]bool, len(protocols))
for _, p := range protocols {
protos[p] = true
@ -155,7 +155,7 @@ func NetProtoCounters(protocols []string) ([]NetProtoCountersStat, error) {
if len(statNames) != len(statValues) {
return nil, errors.New(filename + " is not fomatted correctly, expected same number of columns.")
}
stat := NetProtoCountersStat{
stat := ProtoCountersStat{
Protocol: proto,
Stats: make(map[string]int64, len(statNames)),
}
@ -174,7 +174,7 @@ func NetProtoCounters(protocols []string) ([]NetProtoCountersStat, error) {
// NetFilterCounters returns iptables conntrack statistics
// the currently in use conntrack count and the max.
// If the file does not exist or is invalid it will return nil.
func NetFilterCounters() ([]NetFilterStat, error) {
func FilterCounters() ([]FilterStat, error) {
countfile := common.HostProc("sys/net/netfilter/nf_conntrack_count")
maxfile := common.HostProc("sys/net/netfilter/nf_conntrack_max")
@ -183,14 +183,14 @@ func NetFilterCounters() ([]NetFilterStat, error) {
if err != nil {
return nil, err
}
stats := make([]NetFilterStat, 0, 1)
stats := make([]FilterStat, 0, 1)
max, err := common.ReadInts(maxfile)
if err != nil {
return nil, err
}
payload := NetFilterStat{
payload := FilterStat{
ConnTrackCount: count[0],
ConnTrackMax: max[0],
}
@ -277,12 +277,12 @@ type connTmp struct {
}
// Return a list of network connections opened.
func NetConnections(kind string) ([]NetConnectionStat, error) {
return NetConnectionsPid(kind, 0)
func Connections(kind string) ([]ConnectionStat, error) {
return ConnectionsPid(kind, 0)
}
// Return a list of network connections opened by a process.
func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) {
func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) {
tmap, ok := netConnectionKindMap[kind]
if !ok {
return nil, fmt.Errorf("invalid kind, %s", kind)
@ -296,7 +296,7 @@ func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) {
inodes, err = getProcInodes(root, pid)
if len(inodes) == 0 {
// no connection for the pid
return []NetConnectionStat{}, nil
return []ConnectionStat{}, nil
}
}
if err != nil {
@ -304,7 +304,7 @@ func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) {
}
dupCheckMap := make(map[string]bool)
var ret []NetConnectionStat
var ret []ConnectionStat
for _, t := range tmap {
var path string
@ -322,7 +322,7 @@ func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) {
return nil, err
}
for _, c := range ls {
conn := NetConnectionStat{
conn := ConnectionStat{
Fd: c.fd,
Family: c.family,
Type: c.sockType,

@ -19,7 +19,7 @@ func TestAddrString(t *testing.T) {
}
func TestNetIOCountersStatString(t *testing.T) {
v := NetIOCountersStat{
v := IOCountersStat{
Name: "test",
BytesSent: 100,
}
@ -30,7 +30,7 @@ func TestNetIOCountersStatString(t *testing.T) {
}
func TestNetProtoCountersStatString(t *testing.T) {
v := NetProtoCountersStat{
v := ProtoCountersStat{
Protocol: "tcp",
Stats: map[string]int64{
"MaxConn": -1,
@ -46,7 +46,7 @@ func TestNetProtoCountersStatString(t *testing.T) {
}
func TestNetConnectionStatString(t *testing.T) {
v := NetConnectionStat{
v := ConnectionStat{
Fd: 10,
Family: 10,
Type: 10,
@ -59,8 +59,8 @@ func TestNetConnectionStatString(t *testing.T) {
}
func TestNetIOCountersAll(t *testing.T) {
v, err := NetIOCounters(false)
per, err := NetIOCounters(true)
v, err := IOCounters(false)
per, err := IOCounters(true)
if err != nil {
t.Errorf("Could not get NetIOCounters: %v", err)
}
@ -80,7 +80,7 @@ func TestNetIOCountersAll(t *testing.T) {
}
func TestNetIOCountersPerNic(t *testing.T) {
v, err := NetIOCounters(true)
v, err := IOCounters(true)
if err != nil {
t.Errorf("Could not get NetIOCounters: %v", err)
}
@ -95,20 +95,20 @@ func TestNetIOCountersPerNic(t *testing.T) {
}
func TestGetNetIOCountersAll(t *testing.T) {
n := []NetIOCountersStat{
NetIOCountersStat{
n := []IOCountersStat{
IOCountersStat{
Name: "a",
BytesRecv: 10,
PacketsRecv: 10,
},
NetIOCountersStat{
IOCountersStat{
Name: "b",
BytesRecv: 10,
PacketsRecv: 10,
Errin: 10,
},
}
ret, err := getNetIOCountersAll(n)
ret, err := getIOCountersAll(n)
if err != nil {
t.Error(err)
}
@ -127,7 +127,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
}
func TestNetInterfaces(t *testing.T) {
v, err := NetInterfaces()
v, err := Interfaces()
if err != nil {
t.Errorf("Could not get NetInterfaceStat: %v", err)
}
@ -142,7 +142,7 @@ func TestNetInterfaces(t *testing.T) {
}
func TestNetProtoCountersStatsAll(t *testing.T) {
v, err := NetProtoCounters(nil)
v, err := ProtoCounters(nil)
if err != nil {
t.Fatalf("Could not get NetProtoCounters: %v", err)
}
@ -160,7 +160,7 @@ func TestNetProtoCountersStatsAll(t *testing.T) {
}
func TestNetProtoCountersStats(t *testing.T) {
v, err := NetProtoCounters([]string{"tcp", "ip"})
v, err := ProtoCounters([]string{"tcp", "ip"})
if err != nil {
t.Fatalf("Could not get NetProtoCounters: %v", err)
}
@ -185,7 +185,7 @@ func TestNetConnections(t *testing.T) {
return
}
v, err := NetConnections("inet")
v, err := Connections("inet")
if err != nil {
t.Errorf("could not get NetConnections: %v", err)
}
@ -212,7 +212,7 @@ func TestNetFilterCounters(t *testing.T) {
}
}
v, err := NetFilterCounters()
v, err := FilterCounters()
if err != nil {
t.Errorf("could not get NetConnections: %v", err)
}

@ -9,13 +9,13 @@ import (
)
// Return a list of network connections opened.
func NetConnections(kind string) ([]NetConnectionStat, error) {
return NetConnectionsPid(kind, 0)
func Connections(kind string) ([]ConnectionStat, error) {
return ConnectionsPid(kind, 0)
}
// Return a list of network connections opened by a process.
func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) {
var ret []NetConnectionStat
func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) {
var ret []ConnectionStat
args := []string{"-i"}
switch strings.ToLower(kind) {

@ -30,7 +30,7 @@ const (
TCPTableOwnerModuleAll
)
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
func IOCounters(pernic bool) ([]IOCountersStat, error) {
ifs, err := net.Interfaces()
if err != nil {
return nil, err
@ -40,13 +40,13 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
if err != nil {
return nil, err
}
var ret []NetIOCountersStat
var ret []IOCountersStat
for _, ifi := range ifs {
name := ifi.Name
for ; ai != nil; ai = ai.Next {
name = common.BytePtrToString(&ai.Description[0])
c := NetIOCountersStat{
c := IOCountersStat{
Name: name,
}
@ -69,19 +69,19 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
}
if pernic == false {
return getNetIOCountersAll(ret)
return getIOCountersAll(ret)
}
return ret, nil
}
// NetIOCountersByFile is an method which is added just a compatibility for linux.
func NetIOCountersByFile(pernic bool, filename string) ([]NetIOCountersStat, error) {
return NetIOCounters(pernic)
func IOCountersByFile(pernic bool, filename string) ([]IOCountersStat, error) {
return IOCounters(pernic)
}
// Return a list of network connections opened by a process
func NetConnections(kind string) ([]NetConnectionStat, error) {
var ret []NetConnectionStat
func Connections(kind string) ([]ConnectionStat, error) {
var ret []ConnectionStat
return ret, common.NotImplementedError
}
@ -103,7 +103,7 @@ func getAdapterList() (*syscall.IpAdapterInfo, error) {
return a, nil
}
func NetFilterCounters() ([]NetFilterStat, error) {
func FilterCounters() ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for windows")
}
@ -111,6 +111,6 @@ func NetFilterCounters() ([]NetFilterStat, error) {
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.
// Not Implemented for Windows
func NetProtoCounters(protocols []string) ([]NetProtoCountersStat, error) {
func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for windows")
}

@ -26,7 +26,7 @@ type Process struct {
numThreads int32
memInfo *MemoryInfoStat
lastCPUTimes *cpu.CPUTimesStat
lastCPUTimes *cpu.TimesStat
lastCPUTime time.Time
}
@ -106,8 +106,8 @@ func PidExists(pid int32) (bool, error) {
// If interval is 0, return difference from last call(non-blocking).
// If interval > 0, wait interval sec and return diffrence between start and end.
func (p *Process) CPUPercent(interval time.Duration) (float64, error) {
cpuTimes, err := p.CPUTimes()
func (p *Process) Percent(interval time.Duration) (float64, error) {
cpuTimes, err := p.Times()
if err != nil {
return 0, err
}
@ -117,7 +117,7 @@ func (p *Process) CPUPercent(interval time.Duration) (float64, error) {
p.lastCPUTimes = cpuTimes
p.lastCPUTime = now
time.Sleep(interval)
cpuTimes, err = p.CPUTimes()
cpuTimes, err = p.Times()
now = time.Now()
if err != nil {
return 0, err
@ -139,7 +139,7 @@ func (p *Process) CPUPercent(interval time.Duration) (float64, error) {
return ret, nil
}
func calculatePercent(t1, t2 *cpu.CPUTimesStat, delta float64, numcpu int) float64 {
func calculatePercent(t1, t2 *cpu.TimesStat, delta float64, numcpu int) float64 {
if delta == 0 {
return 0
}

@ -143,7 +143,7 @@ func (p *Process) Uids() ([]int32, error) {
}
// See: http://unix.superglobalmegacorp.com/Net2/newsrc/sys/ucred.h.html
userEffectiveUID := int32(k.Eproc.Ucred.Uid)
userEffectiveUID := int32(k.Eproc.Ucred.UID)
return []int32{userEffectiveUID}, nil
}
@ -210,7 +210,7 @@ func (p *Process) Threads() (map[string]string, error) {
return ret, common.NotImplementedError
}
func convertCpuTimes(s string) (ret float64, err error) {
func convertCPUTimes(s string) (ret float64, err error) {
var t int
var _tmp string
if strings.Contains(s, ":") {
@ -235,23 +235,23 @@ func convertCpuTimes(s string) (ret float64, err error) {
t += h
return float64(t) / ClockTicks, nil
}
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
func (p *Process) Times() (*cpu.TimesStat, error) {
r, err := callPs("utime,stime", p.Pid, false)
if err != nil {
return nil, err
}
utime, err := convertCpuTimes(r[0][0])
utime, err := convertCPUTimes(r[0][0])
if err != nil {
return nil, err
}
stime, err := convertCpuTimes(r[0][1])
stime, err := convertCPUTimes(r[0][1])
if err != nil {
return nil, err
}
ret := &cpu.CPUTimesStat{
ret := &cpu.TimesStat{
CPU: "cpu",
User: utime,
System: stime,
@ -311,11 +311,11 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return net.NetConnectionsPid("all", p.Pid)
func (p *Process) Connections() ([]net.ConnectionStat, error) {
return net.ConnectionsPid("all", p.Pid)
}
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
func (p *Process) IOCounters(pernic bool) ([]net.IOCountersStat, error) {
return nil, common.NotImplementedError
}

@ -101,7 +101,7 @@ type ucred struct {
type Uucred struct {
Ref int32
Uid uint32
UID uint32
Ngroups int16
Pad_cgo_0 [2]byte
Groups [16]uint32
@ -197,7 +197,7 @@ type Au_session struct {
}
type Posix_cred struct {
Uid uint32
UID uint32
Ruid uint32
Svuid uint32
Ngroups int16

@ -184,12 +184,12 @@ func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, common.NotImplementedError
}
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
func (p *Process) Times() (*cpu.TimesStat, error) {
k, err := p.getKProc()
if err != nil {
return nil, err
}
return &cpu.CPUTimesStat{
return &cpu.TimesStat{
CPU: "cpu",
User: float64(k.KiRusage.Utime.Sec) + float64(k.KiRusage.Utime.Usec)/1000000,
System: float64(k.KiRusage.Stime.Sec) + float64(k.KiRusage.Stime.Usec)/1000000,
@ -238,11 +238,11 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
func (p *Process) Connections() ([]net.ConnectionStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
func (p *Process) IOCounters(pernic bool) ([]net.IOCountersStat, error) {
return nil, common.NotImplementedError
}

@ -197,7 +197,7 @@ func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, nil
}
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
func (p *Process) Times() (*cpu.TimesStat, error) {
_, _, cpuTimes, _, _, err := p.fillFromStat()
if err != nil {
return nil, err
@ -254,13 +254,13 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return ret, nil
}
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
return net.NetConnectionsPid("all", p.Pid)
func (p *Process) Connections() ([]net.ConnectionStat, error) {
return net.ConnectionsPid("all", p.Pid)
}
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
func (p *Process) IOCounters(pernic bool) ([]net.IOCountersStat, error) {
filename := common.HostProc(strconv.Itoa(int(p.Pid)), "net/dev")
return net.NetIOCountersByFile(pernic, filename)
return net.IOCountersByFile(pernic, filename)
}
func (p *Process) IsRunning() (bool, error) {
@ -623,7 +623,7 @@ func (p *Process) fillFromStatus() error {
return nil
}
func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32, error) {
func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, int32, error) {
pid := p.Pid
statPath := common.HostProc(strconv.Itoa(int(pid)), "stat")
contents, err := ioutil.ReadFile(statPath)
@ -661,7 +661,7 @@ func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32
return "", 0, nil, 0, 0, err
}
cpuTimes := &cpu.CPUTimesStat{
cpuTimes := &cpu.TimesStat{
CPU: "cpu",
User: float64(utime / ClockTicks),
System: float64(stime / ClockTicks),

@ -244,13 +244,13 @@ func Test_Process_Exe(t *testing.T) {
func Test_Process_CpuPercent(t *testing.T) {
p := testGetProcess()
percent, err := p.CPUPercent(0)
percent, err := p.Percent(0)
if err != nil {
t.Errorf("error %v", err)
}
duration := time.Duration(1000) * time.Microsecond
time.Sleep(duration)
percent, err = p.CPUPercent(0)
percent, err = p.Percent(0)
if err != nil {
t.Errorf("error %v", err)
}
@ -268,7 +268,7 @@ func Test_Process_CpuPercentLoop(t *testing.T) {
for i := 0; i < 2; i++ {
duration := time.Duration(100) * time.Microsecond
percent, err := p.CPUPercent(duration)
percent, err := p.Percent(duration)
if err != nil {
t.Errorf("error %v", err)
}
@ -360,7 +360,7 @@ func Test_CPUTimes(t *testing.T) {
assert.Nil(t, err)
spinSeconds := 0.2
cpuTimes0, err := process.CPUTimes()
cpuTimes0, err := process.Times()
assert.Nil(t, err)
// Spin for a duration of spinSeconds
@ -371,7 +371,7 @@ func Test_CPUTimes(t *testing.T) {
// This block intentionally left blank
}
cpuTimes1, err := process.CPUTimes()
cpuTimes1, err := process.Times()
assert.Nil(t, err)
if cpuTimes0 == nil || cpuTimes1 == nil {

@ -227,7 +227,7 @@ func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, common.NotImplementedError
}
func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) {
func (p *Process) Times() (*cpu.TimesStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) CPUAffinity() ([]int32, error) {
@ -248,11 +248,11 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) Connections() ([]net.NetConnectionStat, error) {
func (p *Process) Connections() ([]net.ConnectionStat, error) {
return nil, common.NotImplementedError
}
func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error) {
func (p *Process) IOCounters(pernic bool) ([]net.IOCountersStat, error) {
return nil, common.NotImplementedError
}

@ -0,0 +1,50 @@
# This script is a helper of migration to gopsutil v2 using gorename
#
# go get golang.org/x/tools/cmd/gorename
TARGETS=`cat <<EOF
CPUTimesStat -> TimesStat
CPUInfoStat -> InfoStat
CPUTimes -> Times
CPUInfo -> Info
CPUCounts -> Counts
CPUPercent -> Percent
DiskUsageStat -> UsageStat
DiskPartitionStat -> PartitionStat
DiskIOCountersStat -> IOCountersStat
DiskPartitions -> Partitions
DiskIOCounters -> IOCounters
DiskUsage -> Usage
HostInfoStat -> InfoStat
HostInfo -> Info
GetVirtualization -> Virtualization
GetPlatformInformation -> PlatformInformation
LoadAvgStat -> AvgStat
LoadAvg -> Avg
NetIOCountersStat -> IOCountersStat
NetConnectionStat -> ConnectionStat
NetProtoCountersStat -> ProtoCountersStat
NetInterfaceAddr -> InterfaceAddr
NetInterfaceStat -> InterfaceStat
NetFilterStat -> FilterStat
NetInterfaces -> Interfaces
getNetIOCountersAll -> getIOCountersAll
NetIOCounters -> IOCounters
NetIOCountersByFile -> IOCountersByFile
NetProtoCounters -> ProtoCounters
NetFilterCounters -> FilterCounters
NetConnections -> Connections
NetConnectionsPid -> ConnectionsPid
Uid -> UID
Id -> ID
convertCpuTimes -> convertCPUTimes
EOF`
IFS=$'\n'
for T in $TARGETS
do
echo $T
gofmt -w -r "$T" ./*.go
done
Loading…
Cancel
Save