diff --git a/pro/logic/status.go b/pro/logic/status.go index 39dccd269..06a111122 100644 --- a/pro/logic/status.go +++ b/pro/logic/status.go @@ -26,10 +26,6 @@ func getNodeStatusOld(node *models.Node) { func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) { - if time.Since(node.LastCheckIn) > models.LastCheckInThreshold { - node.Status = models.OfflineSt - return - } if node.IsStatic { if !node.StaticNode.Enabled { node.Status = models.OfflineSt @@ -53,6 +49,10 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) { node.Status = models.UnKnown return } + if time.Since(node.LastCheckIn) > models.LastCheckInThreshold { + node.Status = models.OfflineSt + return + } host, err := logic.GetHost(node.HostID.String()) if err != nil { node.Status = models.UnKnown @@ -168,9 +168,12 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc if err != nil { continue } - allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false) - if !defaultAclPolicy && !allowed { - continue + + if !defaultAclPolicy { + allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false) + if !allowed { + continue + } } if time.Since(peer.LastCheckIn) > models.LastCheckInThreshold { @@ -181,19 +184,22 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc } // check if peer is in error state checkPeerStatus(&peer, defaultAclPolicy) - if peer.Status == models.ErrorSt { + if peer.Status == models.ErrorSt || peer.Status == models.WarningSt { continue } peerNotConnectedCnt++ } - if peerNotConnectedCnt == 0 { - node.Status = models.OnlineSt + if peerNotConnectedCnt > len(metrics.Connectivity)/2 { + node.Status = models.WarningSt return } + if peerNotConnectedCnt == len(metrics.Connectivity) { node.Status = models.ErrorSt return } - node.Status = models.WarningSt + + node.Status = models.OnlineSt + } diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index f415405f9..267a08bf6 100644 --- a/servercfg/serverconf.go +++ b/servercfg/serverconf.go @@ -654,6 +654,21 @@ func GetMqUserName() string { return password } +// GetMetricInterval - get the publish metric interval +func GetMetricIntervalInMinutes() time.Duration { + //default 15 minutes + mi := "15" + if os.Getenv("PUBLISH_METRIC_INTERVAL") != "" { + mi = os.Getenv("PUBLISH_METRIC_INTERVAL") + } + interval, err := strconv.Atoi(mi) + if err != nil { + interval = 15 + } + + return time.Duration(interval) * time.Minute +} + // GetMetricInterval - get the publish metric interval func GetMetricInterval() string { //default 15 minutes