[ Server ] accomplish alive status precedure
This commit is contained in:
@@ -25,7 +25,7 @@ func NewLogger() (*Logger, error) {
|
||||
LevelKey: "level",
|
||||
TimeKey: "time",
|
||||
//CallerKey: "caller",
|
||||
EncodeLevel: zapcore.CapitalColorLevelEncoder,
|
||||
EncodeLevel: zapcore.CapitalLevelEncoder,
|
||||
EncodeTime: zapcore.RFC3339TimeEncoder,
|
||||
//EncodeCaller: zapcore.FullCallerEncoder,
|
||||
},
|
||||
|
||||
@@ -55,7 +55,7 @@ spring:
|
||||
port: 20672
|
||||
username: boge
|
||||
password: boge8tingH
|
||||
virtual-host: /
|
||||
virtual-host: /wdd
|
||||
listener:
|
||||
simple:
|
||||
retry:
|
||||
|
||||
@@ -30,7 +30,6 @@ func BuildOMsgRuntimeConnectorQueue(agentTopicName string) {
|
||||
|
||||
// 建立 业务消息 返回队列
|
||||
// 统一为 OctopusToServer
|
||||
|
||||
octopusToServerQueueName := agentConfig.GetString("octopus.message.octopus_to_server")
|
||||
|
||||
octopusToServerProp := &ConnectProperty{
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var P = g.G.P
|
||||
@@ -33,11 +32,11 @@ type OctopusMsgBuilder interface {
|
||||
|
||||
type OctopusMessage struct {
|
||||
UUID string `json:"uuid"`
|
||||
InitTime time.Time `json:"init_time" format:"2023-03-21 16:38:30"`
|
||||
InitTime string `json:"init_time" format:"2023-03-21 16:38:30"`
|
||||
Type string `json:"type"`
|
||||
Content interface{} `json:"content"`
|
||||
Result interface{} `json:"result"`
|
||||
ACTime time.Time `json:"ac_time" format:"2023-03-21 16:38:30"`
|
||||
ACTime string `json:"ac_time" format:"2023-03-21 16:38:30"`
|
||||
}
|
||||
|
||||
func (om *OctopusMessage) Handle() {
|
||||
@@ -52,7 +51,7 @@ func (om *OctopusMessage) Send(rabbitQueue *RabbitQueue, msg []byte) {
|
||||
func (om *OctopusMessage) Build(omType string, content interface{}) *OctopusMessage {
|
||||
|
||||
// 当前时间
|
||||
curTimeString := utils.CurTimeString()
|
||||
curTimeString := utils.ParseDateTimeTime()
|
||||
|
||||
// must write to string format, otherwise it's very hard to deserialize
|
||||
bytes, err := json.Marshal(content)
|
||||
@@ -62,11 +61,11 @@ func (om *OctopusMessage) Build(omType string, content interface{}) *OctopusMess
|
||||
|
||||
return &OctopusMessage{
|
||||
UUID: curTimeString,
|
||||
InitTime: time.Now(),
|
||||
InitTime: curTimeString,
|
||||
Type: omType,
|
||||
Content: string(bytes),
|
||||
Result: nil,
|
||||
ACTime: time.Time{},
|
||||
ACTime: curTimeString,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +133,7 @@ func statusOMHandler(octopusMessage *OctopusMessage) {
|
||||
}
|
||||
|
||||
var statusRes string
|
||||
if strings.HasPrefix(statusMessage.Type, "p") {
|
||||
if strings.HasPrefix(statusMessage.StatusType, "P") {
|
||||
// ping info
|
||||
statusRes = status.Ping()
|
||||
} else {
|
||||
@@ -144,7 +143,14 @@ func statusOMHandler(octopusMessage *OctopusMessage) {
|
||||
}
|
||||
|
||||
// 返回消息
|
||||
// 组装消息
|
||||
octopusMessage.ACTime = utils.ParseDateTimeTime()
|
||||
octopusMessage.Result = statusRes
|
||||
// 发送回去
|
||||
statusOctopusReplayMessage, _ := json.Marshal(octopusMessage)
|
||||
OctopusToServerQueue.Send(statusOctopusReplayMessage)
|
||||
|
||||
// 输出日志
|
||||
log.InfoF("接收到查询Agent状态的请求,结果为 => %s", statusRes)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,20 +22,20 @@ func INIT() *AgentServerInfo {
|
||||
// 获取系统的环境变量
|
||||
agentServerInfo := parseAgentServerInfo()
|
||||
|
||||
nacosConfig := g.G.AgentConfig
|
||||
agentConfig := g.G.AgentConfig
|
||||
|
||||
initToServerProp := &rabbitmq.ConnectProperty{
|
||||
ExchangeName: nacosConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: nacosConfig.GetString("octopus.message.init_to_server"),
|
||||
ExchangeName: agentConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: agentConfig.GetString("octopus.message.init_to_server"),
|
||||
ExchangeType: g.QueueDirect,
|
||||
TopicKey: nacosConfig.GetString("octopus.message.init_to_server_key"),
|
||||
TopicKey: agentConfig.GetString("octopus.message.init_to_server_key"),
|
||||
}
|
||||
|
||||
initFromServerProp := &rabbitmq.ConnectProperty{
|
||||
ExchangeName: nacosConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: nacosConfig.GetString("octopus.message.init_from_server"),
|
||||
ExchangeName: agentConfig.GetString("octopus.message.init_exchange"),
|
||||
QueueName: agentConfig.GetString("octopus.message.init_from_server"),
|
||||
ExchangeType: g.QueueDirect,
|
||||
TopicKey: nacosConfig.GetString("octopus.message.init_from_server_key"),
|
||||
TopicKey: agentConfig.GetString("octopus.message.init_from_server_key"),
|
||||
}
|
||||
|
||||
// 建立RabbitMQ的连接
|
||||
@@ -96,6 +96,9 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
|
||||
|
||||
initOctopusMessageDeliveries := initFromServerQueue.Read(false)
|
||||
|
||||
// 2023年6月19日 修复注册信息一直没有完全消费的问题
|
||||
findRealAgentTopicName := ""
|
||||
|
||||
// 同步很多抢占注册的情况
|
||||
for delivery := range initOctopusMessageDeliveries {
|
||||
|
||||
@@ -128,29 +131,34 @@ func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToSe
|
||||
// 修改系统参数
|
||||
g.G.AgentHasRegister = true
|
||||
|
||||
// 建立 运行时 RabbitMQ连接
|
||||
agentTopicName := initOctopusMsg.Result.(string)
|
||||
rabbitmq.BuildOMsgRuntimeConnectorQueue(agentTopicName)
|
||||
// 保存真实的AgentTopicName
|
||||
findRealAgentTopicName = serverInfo.TopicName
|
||||
|
||||
// 手动关闭 注册队列的连接
|
||||
shutdownRegisterQueueConnection(initFromServerQueue, initToServerQueue)
|
||||
return
|
||||
|
||||
} else {
|
||||
// 不是自身的 注册回复信息 -- 拒绝 2023年6月19日 此处存在错误! 会死循环Nack 导致异常
|
||||
log.Warn(fmt.Sprintf("OctopusMessage INIT from server not this agent ! => %v, ==>%s", initOctopusMsg, delivery.Body))
|
||||
delivery.Ack(false)
|
||||
|
||||
// 需要休眠等待不再获取相应的信息
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
|
||||
// 不是自身的 注册回复信息 -- 拒绝
|
||||
log.Warn(fmt.Sprintf("OctopusMessage INIT from server not this agent ! => %v, ==>%s", initOctopusMsg, delivery.Body))
|
||||
delivery.Nack(false, true)
|
||||
|
||||
// 需要休眠等待不再获取相应的信息
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
}
|
||||
|
||||
// 建立 运行时 RabbitMQ连接
|
||||
rabbitmq.BuildOMsgRuntimeConnectorQueue(findRealAgentTopicName)
|
||||
|
||||
}
|
||||
|
||||
// shutdownRegisterQueueConnection 关闭初始化连接的两个队列
|
||||
func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue) {
|
||||
log.InfoF("Shutdown register queue connection !")
|
||||
|
||||
initFromServerQueue.Close()
|
||||
initToServerQueue.Close()
|
||||
|
||||
log.InfoF("Pretend to Shutdown register queue connection !")
|
||||
}
|
||||
|
||||
func parseAgentServerInfo() *AgentServerInfo {
|
||||
|
||||
@@ -22,5 +22,5 @@ type AgentServerInfo struct {
|
||||
Comment string `json:"comment" yaml:"comment"`
|
||||
MachineID string `json:"machineId" yaml:"machineId"`
|
||||
AgentVersion string `json:"agentVersion" yaml:"agentVersion"`
|
||||
AgentTopicName string `json:"agentTopicName" yaml:"agentTopicName"`
|
||||
TopicName string `json:"topicName" yaml:"topicName"`
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ osKernelInfo: "5.4.0-135-generic"
|
||||
tcpControl: "cubic"
|
||||
virtualization: "Dedicated"
|
||||
ioSpeed: "150 MB/s"
|
||||
machineId: ""
|
||||
machineId: "fakemachinid123"
|
||||
agentVersion: ""
|
||||
agentTopicName: ""
|
||||
topicName: ""
|
||||
|
||||
@@ -11,14 +11,13 @@ var log = logger2.Log
|
||||
type StatusMessage struct {
|
||||
/**
|
||||
* which kind of status should be return
|
||||
* metric => short time message
|
||||
* all => all agent status message
|
||||
* healthy => check for healthy
|
||||
"PING";
|
||||
* METRIC => short time message
|
||||
* ALL => all agent status message
|
||||
* */
|
||||
Type string `json:"type,omitempty"`
|
||||
AgentTopicName string `json:"agent_topic_name,omitempty"`
|
||||
MetricRepeatCount int `json:"metric_repeat_count,omitempty"`
|
||||
metricRepeatPinch int `json:"metric_repeat_pinch,omitempty"`
|
||||
StatusType string `json:"statusType,omitempty"`
|
||||
MetricRepeatCount int `json:"metricRepeatCount,omitempty"`
|
||||
metricRepeatPinch int `json:"metricRepeatPinch,omitempty"`
|
||||
}
|
||||
|
||||
type AgentStatus struct {
|
||||
|
||||
5
agent-go/tmp/init-from-server-message.json
Normal file
5
agent-go/tmp/init-from-server-message.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"uuid\":\"Chengdu-amd64-98-fakema\",\"init_time\":\"2023-06-19 15:21:02\",\"type\":\"INIT\",\"content\":\"{\\\"serverName\\\":\\\"Chengdu-amd64-98\\\",\\\"serverIpPbV4\\\":\\\"183.220.149.17\\\",\\\"serverIpInV4\\\":\\\"\\\",\\\"serverIpPbV6\\\":\\\"\\\",\\\"serverIpInV6\\\":\\\"\\\",\\\"registerTime\\\":null,\\\"expireTime\\\":null,\\\"createTime\\\":null,\\\"updateTime\\\":null,\\\"proxyType\\\":null,\\\"location\\\":\\\"Chengdu Sichuan CN\\\",\\\"provider\\\":\\\"AS139080 The Internet Data Center of Sichuan Mobile Communication Company Limited\\\",\\\"managePort\\
|
||||
\
|
||||
":\\\"22\\\",\\\"cpuBrand\\\":\\\"Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz\\\",\\\"cpuCore\\\":\\\"12 @ 4299.998 MHz\\\",\\\"memoryTotal\\\":\\\"7.6 GB\\\",\\\"diskTotal\\\":\\\"914.9 GB\\\",\\\"diskUsage\\\":\\\"12.3 GB\\\",\\\"ioSpeed\\\":\\\"150 MB/s\\\",\\\"tcpControl\\\":\\\"cubic\\\",\\\"virtualization\\\":\\\"Dedicated\\\",\\\"osInfo\\\":\\\"Ubuntu 20.04.5 LTS\\\",\\\"osKernelInfo\\\":\\\"5.4.0-135-generic\\\",\\\"machineId\\\":\\\"fakemachinid123\\\",\\\"topicName\\\":\\\"Chengdu-amd64-98-fakema\\\",\\\"comment\\\":\\\"\\\",\\\"agentVersion\\\":\\\"\\\"}\",\"result\":null,\"ac_time\":null}"
|
||||
}
|
||||
8
agent-go/tmp/init-to-server-message.json
Normal file
8
agent-go/tmp/init-to-server-message.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"uuid": "2023-06-19 14:29:20",
|
||||
"init_time": "2023-06-19 14:29:20",
|
||||
"type": "INIT",
|
||||
"content": "{\"serverName\":\"Chengdu-amd64-98\",\"serverIpPbV4\":\"183.220.149.17\",\"serverIpInV4\":\"\",\"serverIpPbV6\":\"\",\"serverIpInV6\":\"\",\"location\":\"Chengdu Sichuan CN\",\"provider\":\"AS139080 The Internet Data Center of Sichuan Mobile Communication Company Limited\",\"managePort\":\"22\",\"cpuCore\":\"12 @ 4299.998 MHz\",\"cpuBrand\":\"Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz\",\"osInfo\":\"Ubuntu 20.04.5 LTS\",\"osKernelInfo\":\"5.4.0-135-generic\",\"tcpControl\":\"cubic\",\"virtualization\":\"Dedicated\",\"ioSpeed\":\"150 MB/s\",\"memoryTotal\":\"7.6 GB\",\"diskTotal\":\"914.9 GB\",\"diskUsage\":\"12.3 GB\",\"comment\":\"\",\"machineId\":\"\",\"agentVersion\":\"\",\"agentTopicName\":\"\"}",
|
||||
"result": null,
|
||||
"ac_time": "2023-06-19 14:29:20"
|
||||
}
|
||||
@@ -4,13 +4,18 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// CurTimeString 输出系统时间的格式为"2006-01-02 15:04:05"形式的时间字符串
|
||||
func CurTimeString() string {
|
||||
// ParseDateTimeTime 输出系统时间的格式为"2006-01-02 15:04:05"形式的时间字符串
|
||||
func ParseDateTimeTime() string {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
/*loc := time.FixedZone("UTC+8", 8*60*60) // 创建东八区时区对象
|
||||
localTime := now.In(loc) // 转换为东八区时间*/
|
||||
|
||||
return now.Format("2006-01-02 15:04:05")
|
||||
return now.Format(time.DateTime)
|
||||
}
|
||||
|
||||
func ParseISOLocalDateTime() string {
|
||||
now := time.Now()
|
||||
return now.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user