From 443fb992699818305e3d7f6885ca7d1d36fbe7cd Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 01 十一月 2023 15:47:57 +0800
Subject: [PATCH] 增加系统运行时间,系统状态,集群状态,集群节点数

---
 conf/config.go |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/conf/config.go b/conf/config.go
index ad8f0cc..53632ae 100644
--- a/conf/config.go
+++ b/conf/config.go
@@ -4,8 +4,11 @@
 	"apsClient/pkg/convertx"
 	"apsClient/pkg/logx"
 	"apsClient/pkg/sqlitex"
+	"apsClient/pkg/timex"
+	"apsClient/utils"
 	"github.com/spf13/viper"
 	"log"
+	"time"
 )
 
 var (
@@ -104,7 +107,11 @@
 
 		CurrentDeviceID string //璁剧疆褰撳墠闈㈡澘鎺у埗鐨勮澶�
 
-		SerfClusterStatus string
+		SerfClusterStatus string //闆嗙兢鐘舵��
+
+		ClusterNodeQuantity int //闆嗙兢鑺傜偣鏁伴噺
+
+		SystemDeviceRunSince int64 //绯荤粺寮�濮嬭繍琛屾椂闂存埑
 	}
 )
 
@@ -130,6 +137,19 @@
 	if Conf.PLC.StandbyTime == 0 {
 		Conf.PLC.StandbyTime = 300 //5鍒嗛挓
 	}
+
+	uptimeStr, err := utils.Exec("uptime -s")
+	if err == nil {
+		t, err := timex.StringToTime(uptimeStr)
+		if err == nil {
+			Conf.SystemDeviceRunSince = t.Unix()
+		}
+	} else {
+		Conf.SystemDeviceRunSince = time.Now().Unix()
+	}
+
+	SetUpTime()
+
 	ShowConfig()
 }
 
@@ -150,3 +170,15 @@
 	log.Printf("   services :                  %+v", Conf.Services)
 	log.Println("......................................................")
 }
+
+func SetUpTime() {
+	uptimeStr, err := utils.Exec("uptime -s")
+	if err == nil {
+		t, err := timex.StringToTime(uptimeStr)
+		if err == nil {
+			Conf.SystemDeviceRunSince = t.Unix()
+		}
+	} else {
+		Conf.SystemDeviceRunSince = time.Now().Unix()
+	}
+}

--
Gitblit v1.8.0