making lots of progress!

This commit is contained in:
2025-07-24 16:09:00 +02:00
parent c2040a5c08
commit 6b0628792a
28 changed files with 1917 additions and 289 deletions

View File

@@ -1,4 +1,6 @@
// Package netmon provides network interface monitoring with historical data
//
//nolint:mnd
package netmon
import (
@@ -103,11 +105,15 @@ func (m *Monitor) GetStats() []Stats {
rate := m.calculateRate(ifaceStats, rateWindowSeconds)
stats = append(stats, Stats{
Name: name,
BytesSent: ifaceStats.lastSample.BytesSent,
BytesRecv: ifaceStats.lastSample.BytesRecv,
BitsSentRate: uint64(rate.sentRate * bitsPerByte), // Convert to bits/sec
BitsRecvRate: uint64(rate.recvRate * bitsPerByte), // Convert to bits/sec
Name: name,
BytesSent: ifaceStats.lastSample.BytesSent,
BytesRecv: ifaceStats.lastSample.BytesRecv,
BitsSentRate: uint64(
rate.sentRate * bitsPerByte,
), // Convert to bits/sec
BitsRecvRate: uint64(
rate.recvRate * bitsPerByte,
), // Convert to bits/sec
})
}
@@ -141,7 +147,10 @@ type rateInfo struct {
}
// calculateRate calculates the average rate over the last n seconds
func (m *Monitor) calculateRate(ifaceStats *InterfaceStats, seconds int) rateInfo {
func (m *Monitor) calculateRate(
ifaceStats *InterfaceStats,
seconds int,
) rateInfo {
if ifaceStats.count <= 1 {
return rateInfo{}
}
@@ -215,7 +224,8 @@ func (m *Monitor) takeSample() {
for _, counter := range counters {
// Skip loopback and docker interfaces
if counter.Name == "lo" || strings.HasPrefix(counter.Name, "docker") {
if counter.Name == "lo" ||
strings.HasPrefix(counter.Name, "docker") {
continue
}