Files
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

35 lines
1016 B
Go

package hostcollect
import (
"fmt"
"math"
"strings"
)
// maxUptimeSeconds is the bound internal/host enforces (100 years). Rejecting here
// keeps an implausible reading from failing normalization later, where the cause is
// harder to see.
const maxUptimeSeconds = 100 * 365 * 24 * 60 * 60
// parseUptime reads the first field of /proc/uptime, the seconds since boot. The
// second field (idle time summed over cores) is intentionally unused.
func parseUptime(data []byte) (float64, error) {
fields := strings.Fields(string(data))
if len(fields) == 0 {
return 0, errBadUptime
}
seconds, ok := parseFloat(fields[0])
if !ok || seconds < 0 || seconds > maxUptimeSeconds || math.IsNaN(seconds) || math.IsInf(seconds, 0) {
return 0, errBadUptime
}
return seconds, nil
}
func (c *Collector) uptimeSeconds() (float64, error) {
data, err := readLimited(c.procPath("uptime"), maxProcessFileBytes)
if err != nil {
return 0, fmt.Errorf("hostcollect: read uptime: %w", err)
}
return parseUptime(data)
}