Add per-interface packet and byte rate statistics

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-26 11:16:32 -08:00
parent 353c1ad701
commit 7c978d28ac
3 changed files with 168 additions and 19 deletions

View File

@@ -111,10 +111,14 @@ type Interface struct {
}
type InterfaceStats struct {
Speed uint64 `json:"speed,omitempty"`
InErrors uint64 `json:"in_errors,omitempty"`
OutErrors uint64 `json:"out_errors,omitempty"`
PoE *PoEStats `json:"poe,omitempty"`
Speed uint64 `json:"speed,omitempty"`
InErrors uint64 `json:"in_errors,omitempty"`
OutErrors uint64 `json:"out_errors,omitempty"`
InPktsRate float64 `json:"in_pkts_rate,omitempty"`
OutPktsRate float64 `json:"out_pkts_rate,omitempty"`
InBytesRate float64 `json:"in_bytes_rate,omitempty"`
OutBytesRate float64 `json:"out_bytes_rate,omitempty"`
PoE *PoEStats `json:"poe,omitempty"`
}
type PoEStats struct {
@@ -195,6 +199,10 @@ func (s *InterfaceStats) String() string {
parts = append(parts, fmt.Sprintf("err:%d/%d", s.InErrors, s.OutErrors))
}
if s.InBytesRate > 0 || s.OutBytesRate > 0 {
parts = append(parts, fmt.Sprintf("%.0f/%.0fB/s", s.InBytesRate, s.OutBytesRate))
}
if s.PoE != nil {
if s.PoE.MaxPower > 0 {
parts = append(parts, fmt.Sprintf("poe:%.1f/%.1fW", s.PoE.Power, s.PoE.MaxPower))