mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-14 09:04:44 +08:00
commit
5ae7473906
3 changed files with 46 additions and 19 deletions
|
@ -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
|
||||
|
@ -71,11 +71,15 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if metrics == nil || metrics.Connectivity == nil {
|
||||
if metrics == nil || metrics.Connectivity == nil || len(metrics.Connectivity) == 0 {
|
||||
if time.Since(node.LastCheckIn) < models.LastCheckInThreshold {
|
||||
node.Status = models.OnlineSt
|
||||
return
|
||||
}
|
||||
if node.LastCheckIn.IsZero() {
|
||||
node.Status = models.OfflineSt
|
||||
return
|
||||
}
|
||||
}
|
||||
// if node.IsFailOver {
|
||||
// if time.Since(node.LastCheckIn) < models.LastCheckInThreshold {
|
||||
|
@ -133,9 +137,12 @@ func checkPeerStatus(node *models.Node, defaultAclPolicy bool) {
|
|||
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 {
|
||||
|
@ -154,7 +161,7 @@ func checkPeerStatus(node *models.Node, defaultAclPolicy bool) {
|
|||
node.Status = models.OnlineSt
|
||||
return
|
||||
}
|
||||
if peerNotConnectedCnt == len(metrics.Connectivity) {
|
||||
if len(metrics.Connectivity) > 0 && peerNotConnectedCnt == len(metrics.Connectivity) {
|
||||
node.Status = models.ErrorSt
|
||||
return
|
||||
}
|
||||
|
@ -168,9 +175,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 +191,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) {
|
||||
|
||||
if len(metrics.Connectivity) > 0 && peerNotConnectedCnt == len(metrics.Connectivity) {
|
||||
node.Status = models.ErrorSt
|
||||
return
|
||||
}
|
||||
node.Status = models.WarningSt
|
||||
|
||||
node.Status = models.OnlineSt
|
||||
|
||||
}
|
||||
|
|
|
@ -617,8 +617,7 @@ install_netmaker() {
|
|||
|
||||
echo "Pulling config files..."
|
||||
|
||||
|
||||
local BASE_URL="https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG"
|
||||
local BASE_URL="https://raw.githubusercontent.com/gravitl/netmaker/master"
|
||||
local COMPOSE_URL="$BASE_URL/compose/docker-compose.yml"
|
||||
local CADDY_URL="$BASE_URL/docker/Caddyfile"
|
||||
if [ "$INSTALL_TYPE" = "pro" ]; then
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue