Skip to content

Commit

Permalink
Remove extraneous development note comments
Browse files Browse the repository at this point in the history
Move a function from nocgo to main file for disk package
  • Loading branch information
Dylan Myers committed May 22, 2024
1 parent df9c9bf commit ff4ae36
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 47 deletions.
32 changes: 32 additions & 0 deletions disk/disk_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package disk

import (
"context"
"errors"
"strings"

"github.com/shirou/gopsutil/v3/internal/common"
)
Expand All @@ -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")
}
5 changes: 0 additions & 5 deletions disk/disk_aix_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"

"github.com/power-devops/perfstat"
"github.com/shirou/gopsutil/v3/internal/common"
)

var FSType map[int]string
Expand Down Expand Up @@ -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
}
38 changes: 0 additions & 38 deletions disk/disk_aix_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package disk

import (
"context"
"errors"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -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")
}
11 changes: 7 additions & 4 deletions host/host_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ff4ae36

Please sign in to comment.