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

---
 serf/sync.go |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/serf/sync.go b/serf/sync.go
index d8ef4c7..16d19ac 100644
--- a/serf/sync.go
+++ b/serf/sync.go
@@ -5,6 +5,7 @@
 	"context"
 	"encoding/json"
 	"fmt"
+	"github.com/mitchellh/mapstructure"
 	"os"
 	"os/signal"
 	"regexp"
@@ -311,7 +312,7 @@
 }
 
 // 鏌ヨ闆嗙兢鐘舵��, 杩斿洖 master, slave, leave
-func (ss *SyncServer) QueryClusterStat() string {
+func (ss *SyncServer) QueryClusterStat() *bhomeclient.Reply {
 	clusterStatTopic := "/data/api-v/cluster/status"
 	req := bhomeclient.Request{
 		Path:   clusterStatTopic,
@@ -322,14 +323,14 @@
 	if err != nil {
 		fmt.Println("RequestTopic error", err.Error())
 
-		return ""
+		return reply
 	}
 
 	ss.ClusterStatus = reply.Msg
 
 	logx.Debugf("褰撳墠闆嗙兢鐘舵��: %s", ss.ClusterStatus)
 
-	return reply.Msg
+	return reply
 }
 
 func (ss *SyncServer) handleDbLoggerPrint() {
@@ -439,7 +440,7 @@
 	return err
 }
 
-func (ss *SyncServer)Print(values ...interface{}) {
+func (ss *SyncServer) Print(values ...interface{}) {
 	var (
 		level = values[0]
 	)
@@ -519,3 +520,28 @@
 
 	return ""
 }
+
+type NodeInfo struct {
+	NodeID     string `json:"node_id,omitempty"`
+	NodeIp     string `json:"node_ip,omitempty"`
+	NodeName   string `json:"node_name,omitempty"`
+	ClusterID  string `json:"cluster_id"`
+	CreateTime string `json:"create_time"`
+	DeviceType string `json:"device_type"`
+	DriftState string `json:"drift_state"`
+	Online     string `json:"online"`
+}
+
+func QueryClusterStatusAndNodeQuantity() (string, int) {
+	reply := agent.QueryClusterStat()
+	if reply == nil {
+		return "", 0
+	}
+	var nodes []NodeInfo
+	err := mapstructure.Decode(reply.Data, &nodes)
+	if err != nil {
+		logx.Errorf("mapstructure.Decode QueryClusterStat data err:%v", err)
+		return reply.Msg, 0
+	}
+	return reply.Msg, len(nodes)
+}

--
Gitblit v1.8.0