check last check in against metrics interval

This commit is contained in:
abhishek9686 2025-01-07 21:23:49 +05:30
parent 088b4ef82b
commit 739f6ade90
2 changed files with 20 additions and 0 deletions

View file

@ -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

View file

@ -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