Remove extraneous development note comments

Move a function from nocgo to main file for disk package
pull/1651/head
Dylan Myers 10 months ago
parent df9c9bf340
commit ff4ae36cc0

@ -5,6 +5,8 @@ package disk
import (
"context"
"errors"
"strings"
"github.com/shirou/gopsutil/v3/internal/common"
)
@ -16,3 +18,33 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC
func LabelWithContext(ctx context.Context, name string) (string, error) {
return "", common.ErrNotImplementedError
}
// Using lscfg and a device name, we can get the device information
// This is a pure go implementation, and should be moved to disk_aix_nocgo.go
// if a more efficient CGO method is introduced in disk_aix_cgo.go
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
// This isn't linux, these aren't actual disk devices
if strings.HasPrefix(name, "/dev/") {
return "", errors.New("devices on /dev are not physical disks on aix")
}
out, err := invoke.CommandWithContext(ctx, "lscfg", "-vl", name)
if err != nil {
return "", err
}
ret := ""
// Kind of inefficient, but it works
lines := strings.Split(string(out[:]), "\n")
for line := 1; line < len(lines); line++ {
v := strings.TrimSpace(lines[line])
if strings.HasPrefix(v, "Serial Number...............") {
ret = strings.TrimPrefix(v, "Serial Number...............")
if ret == "" {
return "", errors.New("empty serial for disk")
}
return ret, nil
}
}
return ret, errors.New("serial entry not found for disk")
}

@ -8,7 +8,6 @@ import (
"fmt"
"github.com/power-devops/perfstat"
"github.com/shirou/gopsutil/v3/internal/common"
)
var FSType map[int]string
@ -75,7 +74,3 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
}
return nil, fmt.Errorf("mountpoint %s not found", path)
}
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
return "", common.ErrNotImplementedError
}

@ -5,7 +5,6 @@ package disk
import (
"context"
"errors"
"regexp"
"strconv"
"strings"
@ -186,40 +185,3 @@ func GetMountFSTypeWithContext(ctx context.Context, mp string) (string, error) {
return "", nil
}
// Using lscfg and a device name, we can get the device information
// # lscfg -vl hdisk2
// hdisk2 U8284.22A.21D72DW-V19-C22-T1-W500507680304A7D2-L2000000000000 MPIO FC 2145
// Manufacturer................IBM
// Machine Type and Model......2145
// ROS Level and ID............0000
// Device Specific.(Z0)........0000063268181002
// Device Specific.(Z1)........00c0204
// Serial Number...............600507630081029F5000000000000015
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
// This isn't linux, these aren't actual disk devices
if strings.HasPrefix(name, "/dev/") {
return "", errors.New("devices on /dev are not physical disks on aix")
}
out, err := invoke.CommandWithContext(ctx, "lscfg", "-vl", name)
if err != nil {
return "", err
}
ret := ""
// Kind of inefficient, but it works
lines := strings.Split(string(out[:]), "\n")
for line := 1; line < len(lines); line++ {
v := strings.TrimSpace(lines[line])
if strings.HasPrefix(v, "Serial Number...............") {
ret = strings.TrimPrefix(v, "Serial Number...............")
if ret == "" {
return "", errors.New("empty serial for disk")
}
return ret, nil
}
}
return ret, errors.New("serial entry not found for disk")
}

@ -47,10 +47,13 @@ func BootTimeWithContext(ctx context.Context) (btime uint64, err error) {
return timeSince(ut), nil
}
//11:54AM up 13 mins, 1 user, load average: 2.78, 2.62, 1.79
//12:41PM up 1 hr, 1 user, load average: 2.47, 2.85, 2.83
//07:43PM up 5 hrs, 1 user, load average: 3.27, 2.91, 2.72
//11:18:23 up 83 days, 18:29, 4 users, load average: 0.16, 0.03, 0.01
// This function takes multiple formats of output frmo the uptime
// command and converts the data into minutes.
// Some examples of uptime output that this command handles:
// 11:54AM up 13 mins, 1 user, load average: 2.78, 2.62, 1.79
// 12:41PM up 1 hr, 1 user, load average: 2.47, 2.85, 2.83
// 07:43PM up 5 hrs, 1 user, load average: 3.27, 2.91, 2.72
// 11:18:23 up 83 days, 18:29, 4 users, load average: 0.16, 0.03, 0.01
func UptimeWithContext(ctx context.Context) (uint64, error) {
out, err := invoke.CommandWithContext(ctx, "uptime")
if err != nil {

Loading…
Cancel
Save