Publish ITWorx Pulse source
Public source validation / validate (push) Failing after 3m8s

This commit is contained in:
ITWorx Pulse release export
2026-09-03 02:09:19 +02:00
commit bd774932d5
614 changed files with 77116 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
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)
}