Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// A new process gets a new identity, even when a container reuses PID 1.
|
|
var resourceProcessID = uuid.NewString()
|
|
|
|
type processIOCounters struct {
|
|
Scope string `json:"scope"`
|
|
Available bool `json:"available"`
|
|
ProcessID string `json:"process_id"`
|
|
ReadBytes uint64 `json:"read_bytes"`
|
|
WriteBytes uint64 `json:"write_bytes"`
|
|
}
|
|
|
|
func readProcessIO() processIOCounters {
|
|
data, _ := os.ReadFile("/proc/self/io")
|
|
return parseProcessIO(string(data))
|
|
}
|
|
|
|
func parseProcessIO(data string) processIOCounters {
|
|
result := processIOCounters{Scope: "process", ProcessID: resourceProcessID}
|
|
read, write := false, false
|
|
for _, line := range strings.Split(data, "\n") {
|
|
fields := strings.Fields(line)
|
|
if len(fields) != 2 {
|
|
continue
|
|
}
|
|
if fields[0] != "read_bytes:" && fields[0] != "write_bytes:" {
|
|
continue
|
|
}
|
|
value, err := strconv.ParseUint(fields[1], 10, 64)
|
|
if err != nil {
|
|
return result
|
|
}
|
|
if fields[0] == "read_bytes:" {
|
|
result.ReadBytes = value
|
|
read = true
|
|
} else {
|
|
result.WriteBytes = value
|
|
write = true
|
|
}
|
|
}
|
|
result.Available = read && write
|
|
return result
|
|
}
|