From 768c3b18888db50f848481e713106e655fba6df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Fri, 22 Oct 2021 18:22:07 +0300 Subject: [PATCH 1/3] [mem][solaris] don't hardcode path to prtconf in error message --- mem/mem_solaris.go | 3 +-- v3/mem/mem_solaris.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mem/mem_solaris.go b/mem/mem_solaris.go index 4cacde1d..0c27bd0b 100644 --- a/mem/mem_solaris.go +++ b/mem/mem_solaris.go @@ -4,7 +4,6 @@ package mem import ( "context" - "errors" "fmt" "os/exec" "regexp" @@ -84,7 +83,7 @@ func globalZoneMemoryCapacity() (uint64, error) { match := globalZoneMemoryCapacityMatch.FindAllStringSubmatch(string(out), -1) if len(match) != 1 { - return 0, errors.New("memory size not contained in output of /usr/sbin/prtconf") + return 0, fmt.Errorf("memory size not contained in output of %q", prtconf) } totalMB, err := strconv.ParseUint(match[0][1], 10, 64) diff --git a/v3/mem/mem_solaris.go b/v3/mem/mem_solaris.go index 99f5975b..91831d47 100644 --- a/v3/mem/mem_solaris.go +++ b/v3/mem/mem_solaris.go @@ -4,7 +4,6 @@ package mem import ( "context" - "errors" "fmt" "os/exec" "regexp" @@ -84,7 +83,7 @@ func globalZoneMemoryCapacity() (uint64, error) { match := globalZoneMemoryCapacityMatch.FindAllStringSubmatch(string(out), -1) if len(match) != 1 { - return 0, errors.New("memory size not contained in output of /usr/sbin/prtconf") + return 0, fmt.Errorf("memory size not contained in output of %q", prtconf) } totalMB, err := strconv.ParseUint(match[0][1], 10, 64) From 093e68cb9177579635143da7672d7654b63e81d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Fri, 22 Oct 2021 18:27:43 +0300 Subject: [PATCH 2/3] [mem][solaris] improve prtconf memory size scraping Accept uppercase Memory, that's how it appears to be at least in Solaris 11.3 and OpenIndiana oi_151a7. --- mem/mem_solaris.go | 2 +- v3/mem/mem_solaris.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mem/mem_solaris.go b/mem/mem_solaris.go index 0c27bd0b..4d152f47 100644 --- a/mem/mem_solaris.go +++ b/mem/mem_solaris.go @@ -67,7 +67,7 @@ func zoneName() (string, error) { return strings.TrimSpace(string(out)), nil } -var globalZoneMemoryCapacityMatch = regexp.MustCompile(`memory size: ([\d]+) Megabytes`) +var globalZoneMemoryCapacityMatch = regexp.MustCompile(`[Mm]emory size: ([\d]+) Megabytes`) func globalZoneMemoryCapacity() (uint64, error) { prtconf, err := exec.LookPath("prtconf") diff --git a/v3/mem/mem_solaris.go b/v3/mem/mem_solaris.go index 91831d47..6dc849e0 100644 --- a/v3/mem/mem_solaris.go +++ b/v3/mem/mem_solaris.go @@ -67,7 +67,7 @@ func zoneName() (string, error) { return strings.TrimSpace(string(out)), nil } -var globalZoneMemoryCapacityMatch = regexp.MustCompile(`memory size: ([\d]+) Megabytes`) +var globalZoneMemoryCapacityMatch = regexp.MustCompile(`[Mm]emory size: ([\d]+) Megabytes`) func globalZoneMemoryCapacity() (uint64, error) { prtconf, err := exec.LookPath("prtconf") From 09c3ba3896c09c8ee38b8f3a09fcae3370617350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Fri, 22 Oct 2021 18:28:52 +0300 Subject: [PATCH 3/3] [mem][solaris] simplify regular expressions --- mem/mem_solaris.go | 4 ++-- v3/mem/mem_solaris.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mem/mem_solaris.go b/mem/mem_solaris.go index 4d152f47..8b549588 100644 --- a/mem/mem_solaris.go +++ b/mem/mem_solaris.go @@ -67,7 +67,7 @@ func zoneName() (string, error) { return strings.TrimSpace(string(out)), nil } -var globalZoneMemoryCapacityMatch = regexp.MustCompile(`[Mm]emory size: ([\d]+) Megabytes`) +var globalZoneMemoryCapacityMatch = regexp.MustCompile(`[Mm]emory size: (\d+) Megabytes`) func globalZoneMemoryCapacity() (uint64, error) { prtconf, err := exec.LookPath("prtconf") @@ -94,7 +94,7 @@ func globalZoneMemoryCapacity() (uint64, error) { return totalMB * 1024 * 1024, nil } -var kstatMatch = regexp.MustCompile(`([^\s]+)[\s]+([^\s]*)`) +var kstatMatch = regexp.MustCompile(`(\S+)\s+(\S*)`) func nonGlobalZoneMemoryCapacity() (uint64, error) { kstat, err := exec.LookPath("kstat") diff --git a/v3/mem/mem_solaris.go b/v3/mem/mem_solaris.go index 6dc849e0..9f09f82b 100644 --- a/v3/mem/mem_solaris.go +++ b/v3/mem/mem_solaris.go @@ -67,7 +67,7 @@ func zoneName() (string, error) { return strings.TrimSpace(string(out)), nil } -var globalZoneMemoryCapacityMatch = regexp.MustCompile(`[Mm]emory size: ([\d]+) Megabytes`) +var globalZoneMemoryCapacityMatch = regexp.MustCompile(`[Mm]emory size: (\d+) Megabytes`) func globalZoneMemoryCapacity() (uint64, error) { prtconf, err := exec.LookPath("prtconf") @@ -94,7 +94,7 @@ func globalZoneMemoryCapacity() (uint64, error) { return totalMB * 1024 * 1024, nil } -var kstatMatch = regexp.MustCompile(`([^\s]+)[\s]+([^\s]*)`) +var kstatMatch = regexp.MustCompile(`(\S+)\s+(\S*)`) func nonGlobalZoneMemoryCapacity() (uint64, error) { kstat, err := exec.LookPath("kstat")