mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-08 07:41:41 +08:00
fix metric bytes sent/recv issue (#3166)
This commit is contained in:
parent
4ec1ea4831
commit
2426b5fd39
2 changed files with 19 additions and 14 deletions
|
|
@ -19,7 +19,9 @@ type Metric struct {
|
||||||
TotalTime int64 `json:"totaltime" bson:"totaltime" yaml:"totaltime"`
|
TotalTime int64 `json:"totaltime" bson:"totaltime" yaml:"totaltime"`
|
||||||
Latency int64 `json:"latency" bson:"latency" yaml:"latency"`
|
Latency int64 `json:"latency" bson:"latency" yaml:"latency"`
|
||||||
TotalReceived int64 `json:"totalreceived" bson:"totalreceived" yaml:"totalreceived"`
|
TotalReceived int64 `json:"totalreceived" bson:"totalreceived" yaml:"totalreceived"`
|
||||||
|
LastTotalReceived int64 `json:"lasttotalreceived" bson:"lasttotalreceived" yaml:"lasttotalreceived"`
|
||||||
TotalSent int64 `json:"totalsent" bson:"totalsent" yaml:"totalsent"`
|
TotalSent int64 `json:"totalsent" bson:"totalsent" yaml:"totalsent"`
|
||||||
|
LastTotalSent int64 `json:"lasttotalsent" bson:"lasttotalsent" yaml:"lasttotalsent"`
|
||||||
ActualUptime time.Duration `json:"actualuptime" bson:"actualuptime" yaml:"actualuptime"`
|
ActualUptime time.Duration `json:"actualuptime" bson:"actualuptime" yaml:"actualuptime"`
|
||||||
PercentUp float64 `json:"percentup" bson:"percentup" yaml:"percentup"`
|
PercentUp float64 `json:"percentup" bson:"percentup" yaml:"percentup"`
|
||||||
Connected bool `json:"connected" bson:"connected" yaml:"connected"`
|
Connected bool `json:"connected" bson:"connected" yaml:"connected"`
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -209,15 +208,17 @@ func updateNodeMetrics(currentNode *models.Node, newMetrics *models.Metrics) {
|
||||||
currMetric.TotalTime += oldMetric.TotalTime
|
currMetric.TotalTime += oldMetric.TotalTime
|
||||||
currMetric.Uptime += oldMetric.Uptime // get the total uptime for this connection
|
currMetric.Uptime += oldMetric.Uptime // get the total uptime for this connection
|
||||||
|
|
||||||
if currMetric.TotalReceived < oldMetric.TotalReceived {
|
totalRecv := currMetric.TotalReceived
|
||||||
|
totalSent := currMetric.TotalSent
|
||||||
|
if currMetric.TotalReceived < oldMetric.TotalReceived && currMetric.TotalReceived < oldMetric.LastTotalReceived {
|
||||||
currMetric.TotalReceived += oldMetric.TotalReceived
|
currMetric.TotalReceived += oldMetric.TotalReceived
|
||||||
} else {
|
} else {
|
||||||
currMetric.TotalReceived += int64(math.Abs(float64(currMetric.TotalReceived) - float64(oldMetric.TotalReceived)))
|
currMetric.TotalReceived = currMetric.TotalReceived - oldMetric.LastTotalReceived + oldMetric.TotalReceived
|
||||||
}
|
}
|
||||||
if currMetric.TotalSent < oldMetric.TotalSent {
|
if currMetric.TotalSent < oldMetric.TotalSent && currMetric.TotalSent < oldMetric.LastTotalSent {
|
||||||
currMetric.TotalSent += oldMetric.TotalSent
|
currMetric.TotalSent += oldMetric.TotalSent
|
||||||
} else {
|
} else {
|
||||||
currMetric.TotalSent += int64(math.Abs(float64(currMetric.TotalSent) - float64(oldMetric.TotalSent)))
|
currMetric.TotalSent = currMetric.TotalSent - oldMetric.LastTotalSent + oldMetric.TotalSent
|
||||||
}
|
}
|
||||||
|
|
||||||
if currMetric.Uptime == 0 || currMetric.TotalTime == 0 {
|
if currMetric.Uptime == 0 || currMetric.TotalTime == 0 {
|
||||||
|
|
@ -228,6 +229,8 @@ func updateNodeMetrics(currentNode *models.Node, newMetrics *models.Metrics) {
|
||||||
totalUpMinutes := currMetric.Uptime * ncutils.CheckInInterval
|
totalUpMinutes := currMetric.Uptime * ncutils.CheckInInterval
|
||||||
currMetric.ActualUptime = time.Duration(totalUpMinutes) * time.Minute
|
currMetric.ActualUptime = time.Duration(totalUpMinutes) * time.Minute
|
||||||
delete(oldMetrics.Connectivity, k) // remove from old data
|
delete(oldMetrics.Connectivity, k) // remove from old data
|
||||||
|
currMetric.LastTotalReceived = totalRecv
|
||||||
|
currMetric.LastTotalSent = totalSent
|
||||||
newMetrics.Connectivity[k] = currMetric
|
newMetrics.Connectivity[k] = currMetric
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue