Skip to content

Commit

Permalink
util/stats: ignore initial error, push empty stats on initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Jan 21, 2024
1 parent 6392167 commit 816f460
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,10 @@ func ReadClient(id string) (*model.Client, error) {
client := v.(*model.Client)
pkey := client.PublicKey
clientStats, err := stats.GetWireGuardStatsForPeer(pkey)
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("failed to get client stats")
if err == nil {
client.ReceiveBytes = clientStats.ReceivedBytes
client.TransmitBytes = clientStats.TransmittedBytes
}
client.ReceiveBytes = clientStats.ReceivedBytes
client.TransmitBytes = clientStats.TransmittedBytes

return client, nil
}
Expand Down Expand Up @@ -176,13 +173,11 @@ func ReadClients() ([]*model.Client, error) {
cl := c.(*model.Client)
pkey := cl.PublicKey
clientStats, err := stats.GetWireGuardStatsForPeer(pkey)
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("failed to get client stats")
if err == nil {
cl.ReceiveBytes = clientStats.ReceivedBytes
cl.TransmitBytes = clientStats.TransmittedBytes
}
cl.ReceiveBytes = clientStats.ReceivedBytes
cl.TransmitBytes = clientStats.TransmittedBytes

clients = append(clients, cl)
}
}
Expand Down

0 comments on commit 816f460

Please sign in to comment.