updated memory calculation and logo
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -516,4 +517,67 @@ func (m *Manager) execCommand(name string, args ...string) (string, error) {
|
||||
}
|
||||
|
||||
return stdout.String(), nil
|
||||
}
|
||||
|
||||
// --- Memory helpers ---
|
||||
|
||||
// ParseMemoryMB parses a memory string like "500M", "1G", "1.5G", "1024M", "768"
|
||||
// into megabytes. Returns 0 for empty or unparseable values. Case-insensitive.
|
||||
func ParseMemoryMB(s string) int {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return 0
|
||||
}
|
||||
upper := strings.ToUpper(s)
|
||||
|
||||
if strings.HasSuffix(upper, "GB") {
|
||||
val, err := strconv.ParseFloat(strings.TrimSuffix(upper, "GB"), 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return int(val * 1024)
|
||||
}
|
||||
if strings.HasSuffix(upper, "G") {
|
||||
val, err := strconv.ParseFloat(strings.TrimSuffix(upper, "G"), 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return int(val * 1024)
|
||||
}
|
||||
if strings.HasSuffix(upper, "MB") {
|
||||
val, err := strconv.ParseFloat(strings.TrimSuffix(upper, "MB"), 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return int(val)
|
||||
}
|
||||
if strings.HasSuffix(upper, "M") {
|
||||
val, err := strconv.ParseFloat(strings.TrimSuffix(upper, "M"), 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return int(val)
|
||||
}
|
||||
|
||||
// Plain number — assume MB
|
||||
val, err := strconv.ParseFloat(s, 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return int(val)
|
||||
}
|
||||
|
||||
// CommittedMemory returns the sum of mem_request and mem_limit across all deployed stacks.
|
||||
func (m *Manager) CommittedMemory() (requestMB int, limitMB int) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
for _, s := range m.stacks {
|
||||
if !s.Deployed {
|
||||
continue
|
||||
}
|
||||
requestMB += ParseMemoryMB(s.Meta.Resources.MemRequest)
|
||||
limitMB += ParseMemoryMB(s.Meta.Resources.MemLimit)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user