[agent-go] [status] - test for connect

This commit is contained in:
zeaslity
2023-04-23 16:37:07 +08:00
parent c5143d2d59
commit 9a676b5087
8 changed files with 119 additions and 7 deletions

View File

@@ -3,9 +3,11 @@ package rabbitmq
import (
"agent-go/executor"
"agent-go/g"
"agent-go/status"
"agent-go/utils"
"encoding/json"
"fmt"
"strings"
"time"
)
@@ -105,10 +107,28 @@ func executorOMHandler(octopusMessage *OctopusMessage) {
}
func statusOMHandler(octopusMessage *OctopusMessage) {
log.Info("接收到查询Agent状态的请求假装已经处理")
//statusMessageString := octopusMessage.Content.(string)
statusMsgString := octopusMessage.Content.(string)
var statusMessage *status.StatusMessage
err := json.Unmarshal([]byte(statusMsgString), &statusMessage)
if err != nil {
log.Error(fmt.Sprintf("status message convert to json is wrong! msg is => %s", statusMsgString))
return
}
var statusRes string
if strings.HasPrefix(statusMessage.Type, "p") {
// ping info
statusRes = status.Ping()
} else {
// status info
agentStatusString, _ := json.Marshal(status.ReportAppStatus())
statusRes = string(agentStatusString)
}
// 返回消息
log.InfoF("接收到查询Agent状态的请求结果为 => %s", statusRes)
}
func blackHoleOMHandler(octopusMessage *OctopusMessage) {

View File

@@ -8,6 +8,19 @@ import (
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
* */
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"`
}
type AgentStatus struct {
CPUStatus *CPUStatus
MemoryStatus *MemoryStatus

View File

View File

@@ -0,0 +1,8 @@
{
"uuid": "2023-03-27 14:38:49",
"init_time": "2023-03-27T14:38:49.8162801+08:00",
"type": "PING",
"content": "ping",
"result": "",
"ac_time": "0001-01-01T00:00:00Z"
}