Browse Source

check last check in against metrics interval

abhishek9686 8 tháng trước cách đây
mục cha
commit
739f6ade90
2 tập tin đã thay đổi với 20 bổ sung0 xóa
  1. 5 0
      pro/logic/status.go
  2. 15 0
      servercfg/serverconf.go

+ 5 - 0
pro/logic/status.go

@@ -5,6 +5,7 @@ import (
 
 	"github.com/gravitl/netmaker/logic"
 	"github.com/gravitl/netmaker/models"
+	"github.com/gravitl/netmaker/servercfg"
 )
 
 func getNodeStatusOld(node *models.Node) {
@@ -30,6 +31,10 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
 		node.Status = models.OfflineSt
 		return
 	}
+	if time.Since(node.LastCheckIn) < servercfg.GetMetricIntervalInMinutes() {
+		node.Status = models.OnlineSt
+		return
+	}
 	if node.IsStatic {
 		if !node.StaticNode.Enabled {
 			node.Status = models.OfflineSt

+ 15 - 0
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