status memory info
This commit is contained in:
28
main.go
28
main.go
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -1182,6 +1183,14 @@ func runStatus() error {
|
||||
printInfo("PID", pid, remoteLineColor)
|
||||
}
|
||||
|
||||
if memCurrent, ok := parseSystemdBytes(props["MemoryCurrent"]); ok {
|
||||
memLine := formatBytes(memCurrent)
|
||||
if memPeak, ok := parseSystemdBytes(props["MemoryPeak"]); ok {
|
||||
memLine = fmt.Sprintf("%s (peak: %s)", memLine, formatBytes(memPeak))
|
||||
}
|
||||
printInfo("Memory", memLine, remoteLineColor)
|
||||
}
|
||||
|
||||
if started := strings.TrimSpace(props["ActiveEnterTimestamp"]); started != "" {
|
||||
printInfo("Active since", started, localTimeColor)
|
||||
}
|
||||
@@ -1216,7 +1225,7 @@ func statusColorFor(state string) string {
|
||||
// querySystemdProperties asks systemd for a few service properties.
|
||||
func querySystemdProperties(ctx *deploymentContext) (map[string]string, error) {
|
||||
script := fmt.Sprintf(`set -euo pipefail
|
||||
systemctl show pb@%s -p ActiveState -p SubState -p ActiveEnterTimestamp -p ActiveEnterTimestampMonotonic -p ExecMainPID
|
||||
systemctl show pb@%s -p ActiveState -p SubState -p ActiveEnterTimestamp -p ActiveEnterTimestampMonotonic -p ExecMainPID -p MemoryCurrent -p MemoryPeak
|
||||
`, ctx.serviceName)
|
||||
output, err := runSSHCollect(ctx.serverIP, script)
|
||||
if err != nil {
|
||||
@@ -1225,6 +1234,23 @@ systemctl show pb@%s -p ActiveState -p SubState -p ActiveEnterTimestamp -p Activ
|
||||
return parseKeyValueLines(output), nil
|
||||
}
|
||||
|
||||
func parseSystemdBytes(value string) (int64, bool) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" || value == "0" {
|
||||
return 0, false
|
||||
}
|
||||
if parsed, err := strconv.ParseInt(value, 10, 64); err == nil && parsed > 0 {
|
||||
return parsed, true
|
||||
}
|
||||
if parsed, err := strconv.ParseUint(value, 10, 64); err == nil && parsed > 0 {
|
||||
if parsed > math.MaxInt64 {
|
||||
return 0, false
|
||||
}
|
||||
return int64(parsed), true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func computeUptime(server, startMicro string) time.Duration {
|
||||
startMicro = strings.TrimSpace(startMicro)
|
||||
if startMicro == "" {
|
||||
|
||||
Reference in New Issue
Block a user