0.38.6_agent_hotfix

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-19 08:53:34 +01:00
1 parent 1239ff524d
commit d4a604970e
14 files changed
+478 -162

No files matched your search

+24 -5
View File
@@ -205,16 +205,31 @@ func (c *systemCollector) cpuPercent() *float64 {
if !ok {
return nil
}
c.mu.Lock()
previous := c.cpu
c.mu.Unlock()
if previous == nil {
// Initial sample takes time, but no collector mutex is held.
time.Sleep(200 * time.Millisecond)
next, ok := parseCPUStat(readTrimmed(c.procDir + "/stat"))
if !ok {
return nil
}
previous, sample = &sample, next
initial := sample
sample = next
previous = &initial
}
c.mu.Lock()
if c.cpu != nil {
previous = c.cpu
}
// Concurrent collection must never roll the baseline backwards.
if c.cpu != nil && sample.total < c.cpu.total {
c.mu.Unlock()
return nil
}
c.cpu = &cpuSample{idle: sample.idle, total: sample.total}
c.mu.Unlock()
if sample.total <= previous.total || sample.idle < previous.idle {
return nil
}
@@ -225,8 +240,6 @@ func (c *systemCollector) cpuPercent() *float64 {
}
func (c *systemCollector) collect(ctx context.Context, sock string) *systemInfo {
c.mu.Lock()
defer c.mu.Unlock()
info := &systemInfo{OS: osPrettyName(c.etcDir), Kernel: readTrimmed(c.procDir + "/sys/kernel/osrelease"), Arch: runtime.GOARCH}
if fields := strings.Fields(readTrimmed(c.procDir + "/uptime")); len(fields) > 0 {
if value, err := strconv.ParseFloat(fields[0], 64); err == nil && value >= 0 {
@@ -254,13 +267,19 @@ func (c *systemCollector) collect(ctx context.Context, sock string) *systemInfo
if rx, tx, ok := parseNetDev(readTrimmed(c.procDir + "/net/dev")); ok {
now := time.Now()
info.NetworkRxBytes, info.NetworkTxBytes = ptr(rx), ptr(tx)
if previous := c.net; previous != nil && rx >= previous.rx && tx >= previous.tx {
c.mu.Lock()
previous := c.net
// Do not let an older concurrent poll overwrite a newer sample.
if previous == nil || !now.Before(previous.at) {
c.net = &netSample{rx: rx, tx: tx, at: now}
}
c.mu.Unlock()
if previous != nil && rx >= previous.rx && tx >= previous.tx {
if seconds := now.Sub(previous.at).Seconds(); seconds >= 0.5 {
info.NetworkRxBytesPerSecond = ptr(round(float64(rx-previous.rx)/seconds, 1))
info.NetworkTxBytesPerSecond = ptr(round(float64(tx-previous.tx)/seconds, 1))
}
}
c.net = &netSample{rx: rx, tx: tx, at: now}
}
diskPath := "/"
if sock != "" {