MCPcopy Create free account
hub / github.com/aws/aws-node-termination-handler / UptimeFromFile

Function UptimeFromFile

pkg/uptime/common.go:28–39  ·  view source on GitHub ↗

UptimeFromFile reads system uptime information from filepath and returns the number of seconds since last system boot.

(filepath string)

Source from the content-addressed store, hash-verified

26// UptimeFromFile reads system uptime information from filepath and returns
27// the number of seconds since last system boot.
28func UptimeFromFile(filepath string) (int64, error) {
29 data, err := os.ReadFile(filepath)
30 if err != nil {
31 return 0, fmt.Errorf("not able to read %s: %w", filepath, err)
32 }
33
34 uptime, err := strconv.ParseFloat(strings.Split(string(data), " ")[0], 64)
35 if err != nil {
36 return 0, fmt.Errorf("not able to parse %s to int64: %w", filepath, err)
37 }
38 return int64(uptime), nil
39}

Callers 6

getUptimeFuncFunction · 0.92
getUptimeFromFileFunction · 0.92
UptimeFunction · 0.85

Calls

no outgoing calls

Tested by 4

getUptimeFromFileFunction · 0.74