carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package host
4
5import (
6 "os"
7
8 "golang.org/x/sys/unix"
9)
10
11// readHeadroom reads spare memory from /proc/meminfo and spare disk from
12// the data directory's filesystem. A reading that fails is left at zero.
13func readHeadroom(dataDir string, awake int) *edgeHeadroom {
14 h := &edgeHeadroom{Awake: awake}
15 if b, err := os.ReadFile("/proc/meminfo"); err == nil {
16 h.MemFreeMiB = parseMemAvailableMiB(string(b))
17 }
18 var st unix.Statfs_t
19 if err := unix.Statfs(dataDir, &st); err == nil {
20 h.DiskFreeMiB = int64(st.Bavail) * int64(st.Bsize) / (1 << 20)
21 }
22 return h
23}
24