chore: 统一本地服务器与远程仓库源码
- 合并 main 与 master 历史并以服务器结构为基线 - 保留迁移、数据保留、AWS 账单与部署安全能力 - 建立 SDD 规格和 CI 验证闭环
This commit is contained in:
commit
fd60361d93
460 files changed
+37492
-23871
No files matched your search
@@ -13,6 +13,7 @@ import (
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -161,7 +162,8 @@ func (h *HealthProbeCollector) execTCP(cfg model.ProbeConfig, start time.Time) m
|
||||
timeout = 10 * time.Second
|
||||
}
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", cfg.TCPHost, cfg.TCPPort)
|
||||
// JoinHostPort 兼容 IPv4、主机名与 IPv6 字面量。 // Logan.Li
|
||||
addr := net.JoinHostPort(cfg.TCPHost, strconv.Itoa(cfg.TCPPort))
|
||||
conn, err := net.DialTimeout("tcp", addr, timeout)
|
||||
latencyMs := int(time.Since(start).Milliseconds())
|
||||
result.LatencyMs = latencyMs
|
||||
|
||||
@@ -8,6 +8,7 @@ set -e
|
||||
# 默认参数
|
||||
AIOPS_SERVER=""
|
||||
AGENT_TOKEN=""
|
||||
AGENT_HOSTNAME=""
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
SERVICE_NAME="aiops-agent"
|
||||
PLIST_LABEL="com.ezops.aiops-agent"
|
||||
@@ -34,6 +35,7 @@ while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--server) AIOPS_SERVER="$2"; shift 2;;
|
||||
--token) AGENT_TOKEN="$2"; shift 2;;
|
||||
--hostname) AGENT_HOSTNAME="$2"; shift 2;;
|
||||
--version) AGENT_VERSION="$2"; shift 2;;
|
||||
*) echo "未知参数: $1"; exit 1;;
|
||||
esac
|
||||
@@ -142,6 +144,8 @@ if [ "$OS_LOWER" = "darwin" ]; then
|
||||
<string>10</string>
|
||||
<string>-token</string>
|
||||
<string>${AGENT_TOKEN}</string>
|
||||
<string>-hostname</string>
|
||||
<string>${AGENT_HOSTNAME}</string>
|
||||
</array>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
@@ -193,7 +197,7 @@ Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=${INSTALL_DIR}/aiops-agent -server ${AIOPS_SERVER} -interval 10 -token ${AGENT_TOKEN}
|
||||
ExecStart=${INSTALL_DIR}/aiops-agent -server ${AIOPS_SERVER} -interval 10 -token ${AGENT_TOKEN} -hostname ${AGENT_HOSTNAME}
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
LimitNOFILE=65536
|
||||
|
||||
+6
-10
@@ -116,12 +116,11 @@ func main() {
|
||||
|
||||
sysInfo := collector.CollectSystem()
|
||||
logger.Printf("系统信息: OS=%q Kernel=%q", sysInfo.OSVersion, sysInfo.Kernel)
|
||||
agentStartedAt := time.Now()
|
||||
|
||||
localIP := detectLocalIP()
|
||||
logger.Printf("探测本机 IP: %s", localIP)
|
||||
|
||||
sysReportCount := 0
|
||||
|
||||
taskExecutor := task.New(logger)
|
||||
taskClient := task.NewClient(httpCli, cfg.Hostname, logger)
|
||||
|
||||
@@ -135,20 +134,17 @@ func main() {
|
||||
var probeConfigs []model.ProbeConfig
|
||||
|
||||
collectAndReport := func() {
|
||||
currentUptime := sysInfo.UptimeSeconds + int64(time.Since(agentStartedAt).Seconds())
|
||||
report := &model.Report{
|
||||
Hostname: cfg.Hostname,
|
||||
IP: localIP,
|
||||
Timestamp: time.Now().UTC().Format(time.RFC3339),
|
||||
AgentVersion: version,
|
||||
}
|
||||
|
||||
if sysReportCount < 3 && (sysInfo.OSVersion != "" || sysInfo.Kernel != "") {
|
||||
report.System = &model.SystemStat{
|
||||
System: &model.SystemStat{
|
||||
OSVersion: sysInfo.OSVersion,
|
||||
Kernel: sysInfo.Kernel,
|
||||
Uptime: sysInfo.UptimeSeconds,
|
||||
}
|
||||
sysReportCount++
|
||||
Uptime: currentUptime,
|
||||
},
|
||||
}
|
||||
|
||||
if stat, err := cpuCollector.Collect(); err != nil {
|
||||
@@ -211,7 +207,7 @@ func main() {
|
||||
runtime.ReadMemStats(&memStats)
|
||||
report.Heartbeat = model.AgentHeartbeat{
|
||||
Version: version,
|
||||
UptimeSec: sysInfo.UptimeSeconds,
|
||||
UptimeSec: currentUptime,
|
||||
SelfCPU: 0,
|
||||
SelfRSSMB: float64(memStats.Alloc) / 1024.0 / 1024.0,
|
||||
ReportSeq: reportSeq,
|
||||
|
||||
Reference in new issue
Block a user