Files
mtusi2026lab7/memory.go
T
R0flyan 2fa513f56c
Skeleton contracts / contracts (pull_request) Canceled after 0s
Lab7 HTTPS integration / compose (pull_request) Canceled after 0s
Реализовать защиту Lab7 и проверку отзыва worker
2026-11-27 21:53:26 +03:00

28 lines
709 B
Go

package main
import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
)
// Local operator command, never an HTTP endpoint. cgroup v2 records peaks
// between Docker samples too; the experiment recreates API cgroups per case.
func memorySnapshot() error {
result := map[string]uint64{}
for _, name := range []string{"memory.current", "memory.peak"} {
raw, err := os.ReadFile("/sys/fs/cgroup/" + name)
if err != nil {
return fmt.Errorf("cgroup v2 %s unavailable", name)
}
value, err := strconv.ParseUint(strings.TrimSpace(string(raw)), 10, 64)
if err != nil {
return fmt.Errorf("invalid cgroup %s", name)
}
result[name] = value
}
return json.NewEncoder(os.Stdout).Encode(result)
}