Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions nodestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
// Peer data.
type Peer struct {
PublicKey *key.Public
State admin.PeerState
State string
IsIncoming bool
BytesIn int64
BytesOut int64
BytesIn int
BytesOut int
Last time.Time
SwitchLabel admin.Path
SwitchLabel *admin.Path

IPv6 net.IP
RateIn float64
Expand All @@ -42,7 +42,7 @@ var Data struct {

// Data on this specific node.
Node struct {
Memory int64
Memory int
Angel struct {
Uptime Duration
PercentCPU float64
Expand All @@ -59,8 +59,8 @@ var Data struct {
RateOut float64

// The difference of all bytes received and sent
BytesIn int64
BytesOut int64
BytesIn int
BytesOut int

angelPID []byte
corePID []byte
Expand Down
7 changes: 5 additions & 2 deletions peerStats.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func peerStatLoop() {
}

Data.Node.RateIn, Data.Node.RateOut = 0, 0
Data.Node.BytesIn, Data.Node.BytesOut = int64(0), int64(0)
Data.Node.BytesIn, Data.Node.BytesOut = 0, 0
peerUpdate := make(map[string]Peer)
// loop through the results and update peer statistics while checking
// for any peers that are no longer there.
Expand All @@ -39,12 +39,15 @@ func peerStatLoop() {
newRateIn := float64(peer.BytesIn-Data.Peers[peer.PublicKey.String()].BytesIn) / (time.Since(Data.Peers[peer.PublicKey.String()].LastUpdate).Seconds())
newRateOut := float64(peer.BytesOut-Data.Peers[peer.PublicKey.String()].BytesOut) / (time.Since(Data.Peers[peer.PublicKey.String()].LastUpdate).Seconds())

// Convert the last packet received timestamp to a time.Time
last := time.Unix(0, peer.Last*1000000)

// Update the peer statistics
peerUpdate[peer.PublicKey.String()] = Peer{
PublicKey: peer.PublicKey,
IPv6: Data.Peers[peer.PublicKey.String()].IPv6, // save the same IP
LastUpdate: time.Now(),
Last: peer.Last,
Last: last,
SwitchLabel: peer.SwitchLabel,
IsIncoming: peer.IsIncoming,
State: peer.State,
Expand Down