Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix: host network sparklines showing cumulative bytes instead of rates

rcourtman9d4d392026ce
diff --git a/internal/api/router.go b/internal/api/router.go
index c9c13ba124..9d11f041ba 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -5912,14 +5912,10 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
diskPercent = host.Disks[0].Usage
}
points["disk"] = monitoring.MetricPoint{Timestamp: now, Value: diskPercent}
- // Sum network I/O across all interfaces
- var totalRX, totalTX uint64
- for _, nic := range host.NetworkInterfaces {
- totalRX += nic.RXBytes
- totalTX += nic.TXBytes
- }
- points["netin"] = monitoring.MetricPoint{Timestamp: now, Value: float64(totalRX)}
- points["netout"] = monitoring.MetricPoint{Timestamp: now, Value: float64(totalTX)}
+ // Note: We intentionally don't include netin/netout here because the host model
+ // only has cumulative RXBytes/TXBytes (total since boot), not rates.
+ // The RateTracker in ApplyHostReport calculates rates and stores them in metrics history.
+ // Showing cumulative bytes as if they were rates would be misleading (showing GB instead of KB/s).
case "docker", "dockerContainer":
container := findDockerContainer(resourceID)
if container == nil {
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index ec5ff36291..acaeab0e73 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -2729,12 +2729,23 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
}
// Record host Network I/O (sum across all interfaces)
+ // Network bytes from the agent are cumulative totals since boot, not rates.
+ // We need to use the RateTracker to convert to bytes/second, just like VMs and containers.
var totalRXBytes, totalTXBytes uint64
for _, nic := range host.NetworkInterfaces {
totalRXBytes += nic.RXBytes
totalTXBytes += nic.TXBytes
}
+ // Calculate network rates using the RateTracker (convert cumulative bytes to bytes/sec)
+ hostRateKey := fmt.Sprintf("host:%s", host.ID)
+ currentMetrics := IOMetrics{
+ NetworkIn: int64(totalRXBytes),
+ NetworkOut: int64(totalTXBytes),
+ Timestamp: now,
+ }
+ _, _, netInRate, netOutRate := m.rateTracker.CalculateRates(hostRateKey, currentMetrics)
+
if m.metricsHistory != nil {
// Record host CPU usage
m.metricsHistory.AddGuestMetric(hostMetricKey, "cpu", host.CPUUsage, now)
@@ -2744,8 +2755,13 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
m.metricsHistory.AddGuestMetric(hostMetricKey, "disk", hostDiskPercent, now)
- m.metricsHistory.AddGuestMetric(hostMetricKey, "netin", float64(totalRXBytes), now)
- m.metricsHistory.AddGuestMetric(hostMetricKey, "netout", float64(totalTXBytes), now)
+ // Only record network rates if we have valid data (rate >= 0 means we have enough samples)
+ if netInRate >= 0 {
+ m.metricsHistory.AddGuestMetric(hostMetricKey, "netin", netInRate, now)
+ }
+ if netOutRate >= 0 {
+ m.metricsHistory.AddGuestMetric(hostMetricKey, "netout", netOutRate, now)
+ }
}
// Also write to persistent SQLite store
@@ -2753,8 +2769,13 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
m.metricsStore.Write("host", host.ID, "cpu", host.CPUUsage, now)
m.metricsStore.Write("host", host.ID, "memory", host.Memory.Usage, now)
m.metricsStore.Write("host", host.ID, "disk", hostDiskPercent, now)
- m.metricsStore.Write("host", host.ID, "netin", float64(totalRXBytes), now)
- m.metricsStore.Write("host", host.ID, "netout", float64(totalTXBytes), now)
+ // Only write network rates if we have valid data
+ if netInRate >= 0 {
+ m.metricsStore.Write("host", host.ID, "netin", netInRate, now)
+ }
+ if netOutRate >= 0 {
+ m.metricsStore.Write("host", host.ID, "netout", netOutRate, now)
+ }
}
return host, nil