feat: evect inactive peers
This commit is contained in:
parent
a9c728355b
commit
d6aa213461
12
monitor.go
12
monitor.go
@ -26,18 +26,22 @@ func monitor(wg *WGLink, log slog.Logger) {
|
||||
}
|
||||
|
||||
sb := strings.Builder{}
|
||||
var activePeers int
|
||||
var totalRx int64
|
||||
var totalTx int64
|
||||
for _, peer := range peers {
|
||||
totalRx += peer.ReceiveBytes
|
||||
totalTx += peer.TransmitBytes
|
||||
if isActive(peer) {
|
||||
activePeers += 1
|
||||
if !isActive(peer) {
|
||||
log.Info(
|
||||
fmt.Sprintf("[WGMonitor] Evecting peer %s", peer.PublicKey.String()),
|
||||
)
|
||||
if err := wg.DeletePeer(peer.PublicKey.String()); err != nil {
|
||||
log.Error(err.Error())
|
||||
log.Warn("[WGMonitor] Could not evect peer")
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("Peers: %d ", len(peers)))
|
||||
sb.WriteString(fmt.Sprintf("Active peers: %d ", activePeers))
|
||||
sb.WriteString(fmt.Sprintf("TX: %d RX: %d", totalTx, totalRx))
|
||||
|
||||
log.Info("[WGMonitor] " + sb.String())
|
||||
|
Loading…
Reference in New Issue
Block a user