UptimeFromFile reads system uptime information from filepath and returns the number of seconds since last system boot.
(filepath string)
| 26 | // UptimeFromFile reads system uptime information from filepath and returns |
| 27 | // the number of seconds since last system boot. |
| 28 | func 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 | } |
no outgoing calls