|
|
@@ -346,7 +346,7 @@ func (s *server) ingestBeacon(src string, raw []byte) {
|
|
|
}
|
|
|
ports = append(ports, ep)
|
|
|
}
|
|
|
- s.recordBeaconPortSamples(p.Slug, p.Ports)
|
|
|
+ s.recordBeaconPortSamples(p.Slug, p.Up, p.Ports)
|
|
|
// Alertas SFP (#313): RX baja o temperatura alta en módulos ópticos.
|
|
|
// Se emiten aquí (no en polledFromAgent) para que el dedup del motor
|
|
|
// colapse duplicados entre beacons del mismo switch.
|
|
|
@@ -553,12 +553,42 @@ func (s *server) emitSFPAlerts(slug string, labels map[string]string, sfpByPort
|
|
|
// recordBeaconPortSamples persists beacon frame counts as port series samples
|
|
|
// (issue #302). Beacon ports carry cumulative tx/rx frame counts and link speed
|
|
|
// but no byte counters (the 8051 firmware does not track bytes per port).
|
|
|
-func (s *server) recordBeaconPortSamples(slug string, bps []beaconPort) {
|
|
|
+func (s *server) recordBeaconPortSamples(slug string, up uint32, bps []beaconPort) {
|
|
|
if s.db == nil || s.db.PortSeries == nil || len(bps) == 0 {
|
|
|
return
|
|
|
}
|
|
|
+ // #2221: los contadores viajan en 32 bits y la serie los espera
|
|
|
+ // monótonos. El desenrollo va aquí, con el uptime del datagrama para
|
|
|
+ // distinguir una vuelta de un reinicio; deriveFps no cambia.
|
|
|
+ samples := make([]portseries.PortSample, len(bps))
|
|
|
+ s.beaconCntMu.Lock()
|
|
|
+ if s.beaconCnt == nil {
|
|
|
+ s.beaconCnt = map[string]beaconCounter{}
|
|
|
+ }
|
|
|
+ for i, bp := range bps {
|
|
|
+ portID := fmt.Sprintf("lan%d", bp.N)
|
|
|
+ rxKey := slug + "|" + portID + "|rx"
|
|
|
+ txKey := slug + "|" + portID + "|tx"
|
|
|
+ rxPrev, rxOK := s.beaconCnt[rxKey]
|
|
|
+ txPrev, txOK := s.beaconCnt[txKey]
|
|
|
+ rx, rxNext := unwrapBeaconCounter(rxPrev, rxOK, bp.Rx, up)
|
|
|
+ tx, txNext := unwrapBeaconCounter(txPrev, txOK, bp.Tx, up)
|
|
|
+ s.beaconCnt[rxKey] = rxNext
|
|
|
+ s.beaconCnt[txKey] = txNext
|
|
|
+ samples[i] = portseries.PortSample{
|
|
|
+ RouterID: slug,
|
|
|
+ PortID: portID,
|
|
|
+ RxBytes: uint64(bp.Ih)<<32 | uint64(bp.Il),
|
|
|
+ TxBytes: uint64(bp.Oh)<<32 | uint64(bp.Ol),
|
|
|
+ RxFrames: rx,
|
|
|
+ TxFrames: tx,
|
|
|
+ RxErrors: uint64(bp.Ie),
|
|
|
+ TxErrors: uint64(bp.Oe),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ s.beaconCntMu.Unlock()
|
|
|
now := time.Now()
|
|
|
- for _, bp := range bps {
|
|
|
+ for i, bp := range bps {
|
|
|
if bp.N < 1 || bp.N > 32 {
|
|
|
continue
|
|
|
}
|
|
|
@@ -581,18 +611,10 @@ func (s *server) recordBeaconPortSamples(slug string, bps []beaconPort) {
|
|
|
speedMbps = 10
|
|
|
}
|
|
|
}
|
|
|
- _ = s.db.PortSeries.RecordSample(portseries.PortSample{
|
|
|
- RouterID: slug,
|
|
|
- PortID: fmt.Sprintf("lan%d", bp.N),
|
|
|
- TS: now,
|
|
|
- RxBytes: uint64(bp.Ih)<<32 | uint64(bp.Il),
|
|
|
- TxBytes: uint64(bp.Oh)<<32 | uint64(bp.Ol),
|
|
|
- RxFrames: uint64(bp.Rx),
|
|
|
- TxFrames: uint64(bp.Tx),
|
|
|
- RxErrors: uint64(bp.Ie),
|
|
|
- TxErrors: uint64(bp.Oe),
|
|
|
- SpeedMbps: speedMbps,
|
|
|
- })
|
|
|
+ sample := samples[i]
|
|
|
+ sample.TS = now
|
|
|
+ sample.SpeedMbps = speedMbps
|
|
|
+ _ = s.db.PortSeries.RecordSample(sample)
|
|
|
}
|
|
|
}
|
|
|
|