From 739f6ade90cad27ad7954def496b63d4c7114124 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Tue, 7 Jan 2025 21:23:49 +0530 Subject: [PATCH] check last check in against metrics interval --- pro/logic/status.go | 5 +++++ servercfg/serverconf.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pro/logic/status.go b/pro/logic/status.go index 35ab0b60..ec30ae72 100644 --- a/pro/logic/status.go +++ b/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 diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index f415405f..267a08bf 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