* feat(backend): try a new approach for logs formatting (http) * feat(backend): added logger module * feat(backend): added project/session info to /i endpoint * feat(backend): found a solution for correct caller information * feat(backend): finished logs for http handlers * feat(backend): finished logs for mobile http handlers * feat(backend): finished ender * feat(backend): finished assets * feat(backend): finished heuristics * feat(backend): finished image-storage * feat(backend): finished sink * feat(backend): finished storage * feat(backend): formatted logs in all services * feat(backend): finished foss part * feat(backend): added missed foss part * feat(backend): fixed panic in memory manager and sink service * feat(backend): connectors
41 lines
919 B
Go
41 lines
919 B
Go
package memory
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
Limit = "hierarchical_memory_limit"
|
|
Maximum = 9223372036854771712
|
|
)
|
|
|
|
func parseMemoryLimit() (int, error) {
|
|
data, err := os.ReadFile("/sys/fs/cgroup/memory/memory.stat")
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
lines := strings.Split(string(data), "\n")
|
|
for _, line := range lines {
|
|
if strings.Contains(line, Limit) {
|
|
lineParts := strings.Split(line, " ")
|
|
if len(lineParts) != 2 {
|
|
return 0, fmt.Errorf("can't split string with memory limit, str: %s", line)
|
|
}
|
|
value, err := strconv.Atoi(lineParts[1])
|
|
if err != nil {
|
|
return 0, fmt.Errorf("can't convert memory limit to int, str: %s", lineParts[1])
|
|
}
|
|
if value == Maximum {
|
|
return 0, errors.New("memory limit is not defined")
|
|
}
|
|
// DEBUG_LOG
|
|
value /= 1024 * 1024
|
|
return value, nil
|
|
}
|
|
}
|
|
return 0, errors.New("memory limit is not defined")
|
|
}
|