Skip to content

Commit 2c240c9

Browse files
authored
refactor: reorder fields in Instance struct and update regex for log parsing
1 parent 13c80ab commit 2c240c9

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

internal/master.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ type Instance struct {
8787
Status string `json:"status"` // 实例状态
8888
URL string `json:"url"` // 实例URL
8989
Restart bool `json:"restart"` // 是否自启动
90-
Pool int32 `json:"pool"` // 健康检查池连接数
91-
Ping int32 `json:"ping"` // 健康检查端内延迟
90+
Ping int32 `json:"ping"` // 端内延迟
91+
Pool int32 `json:"pool"` // 池连接数
9292
TCPS int32 `json:"tcps"` // TCP连接数
9393
UDPS int32 `json:"udps"` // UDP连接数
9494
TCPRX uint64 `json:"tcprx"` // TCP接收字节数
@@ -128,7 +128,7 @@ func NewInstanceLogWriter(instanceID string, instance *Instance, target io.Write
128128
instance: instance,
129129
target: target,
130130
master: master,
131-
checkPoint: regexp.MustCompile(`CHECK_POINT\|POOL=(\d+)\|PING=(\d+)ms\|TCPS=(\d+)\|UDPS=(\d+)\|TCP_RX=(\d+)\|TCP_TX=(\d+)\|UDP_RX=(\d+)\|UDP_TX=(\d+)`),
131+
checkPoint: regexp.MustCompile(`CHECK_POINT\|PING=(\d+)ms\|POOL=(\d+)\|TCPS=(\d+)\|UDPS=(\d+)\|TCPRX=(\d+)\|TCPTX=(\d+)\|UDPRX=(\d+)\|UDPTX=(\d+)`),
132132
}
133133
}
134134

@@ -141,13 +141,13 @@ func (w *InstanceLogWriter) Write(p []byte) (n int, err error) {
141141
line := scanner.Text()
142142
// 解析并处理检查点信息
143143
if matches := w.checkPoint.FindStringSubmatch(line); len(matches) == 9 {
144-
// matches[1] = POOL, matches[2] = PING, matches[3] = TCPS, matches[4] = UDPS, matches[5] = TCP_RX, matches[6] = TCP_TX, matches[7] = UDP_RX, matches[8] = UDP_TX
145-
if pool, err := strconv.ParseInt(matches[1], 10, 32); err == nil {
146-
w.instance.Pool = int32(pool)
147-
}
148-
if ping, err := strconv.ParseInt(matches[2], 10, 32); err == nil {
144+
// matches[1] = PING, matches[2] = POOL, matches[3] = TCPS, matches[4] = UDPS, matches[5] = TCPRX, matches[6] = TCPTX, matches[7] = UDPRX, matches[8] = UDPTX
145+
if ping, err := strconv.ParseInt(matches[1], 10, 32); err == nil {
149146
w.instance.Ping = int32(ping)
150147
}
148+
if pool, err := strconv.ParseInt(matches[2], 10, 32); err == nil {
149+
w.instance.Pool = int32(pool)
150+
}
151151
if tcps, err := strconv.ParseInt(matches[3], 10, 32); err == nil {
152152
w.instance.TCPS = int32(tcps)
153153
}
@@ -1364,14 +1364,14 @@ func generateOpenAPISpec() string {
13641364
"status": {"type": "string", "enum": ["running", "stopped", "error"], "description": "Instance status"},
13651365
"url": {"type": "string", "description": "Command string or API Key"},
13661366
"restart": {"type": "boolean", "description": "Restart policy"},
1367+
"ping": {"type": "integer", "description": "Health check ping latency"},
1368+
"pool": {"type": "integer", "description": "Health check pool active"},
1369+
"tcps": {"type": "integer", "description": "TCP connection count"},
1370+
"udps": {"type": "integer", "description": "UDP connection count"},
13671371
"tcprx": {"type": "integer", "description": "TCP received bytes"},
13681372
"tcptx": {"type": "integer", "description": "TCP transmitted bytes"},
13691373
"udprx": {"type": "integer", "description": "UDP received bytes"},
1370-
"udptx": {"type": "integer", "description": "UDP transmitted bytes"},
1371-
"pool": {"type": "integer", "description": "Health check pool active"},
1372-
"ping": {"type": "integer", "description": "Health check one-way latency"},
1373-
"tcps": {"type": "integer", "description": "TCP connection count"},
1374-
"udps": {"type": "integer", "description": "UDP connection count"}
1374+
"udptx": {"type": "integer", "description": "UDP transmitted bytes"}
13751375
}
13761376
},
13771377
"CreateInstanceRequest": {

0 commit comments

Comments
 (0)