diff --git a/scripts/deploy-push-heartbeat.js b/scripts/deploy-push-heartbeat.js index dddaebb..ae439de 100644 --- a/scripts/deploy-push-heartbeat.js +++ b/scripts/deploy-push-heartbeat.js @@ -13,8 +13,8 @@ const SERVERS = [ { code: "BS-SH-005", name: "上海·国内节点", ip: "124.223.10.33", key: "zy_gtw_b1045de5ddfd7832e3c53349d9c896f054b85a4a9ece22f9", port: 3910 }, ]; -const MASTER_HOST = "43.139.217.141"; -const MASTER_PORT = 80; +const MASTER_HOST = "guanghulab.com"; +const MASTER_PORT = 443; const MASTER_PATH = "/console/api/heartbeat"; function gkExec(srv, cmd, timeoutMs) { @@ -39,10 +39,10 @@ function gkExec(srv, cmd, timeoutMs) { // 推送脚本模板 — 通过nginx /console/ → console-server:3920 function pushScript(code, name, key) { return ` -const http=require("http"),os=require("os"); +const https=require("https"),os=require("os"); const HOST="${MASTER_HOST}",PORT=${MASTER_PORT},PATH="${MASTER_PATH}",CODE="${code}",NAME="${name}",KEY="${key}"; function hw(){const c=os.cpus().length,l=os.loadavg(),t=os.totalmem(),f=os.freemem();return{cpu_cores:c,cpu_load:parseFloat(l[0].toFixed(2)),mem_total_mb:Math.floor(t/1048576),mem_used_mb:Math.floor((t-f)/1048576),mem_used_pct:parseFloat(((t-f)/t*100).toFixed(1)),uptime_h:Math.floor(os.uptime()/3600),hostname:os.hostname()}} -function post(d){return new Promise(r=>{const p=JSON.stringify(d),o={hostname:HOST,port:PORT,path:PATH,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(p),"X-Server-Code":CODE,"X-Server-Key":KEY},timeout:8000};const q=http.request(o,res=>{let b="";res.on("data",c=>b+=c);res.on("end",()=>r(res.statusCode===200))});q.on("error",()=>r(false));q.on("timeout",()=>{q.destroy();r(false)});q.write(p);q.end()})} +function post(d){return new Promise(r=>{const p=JSON.stringify(d),o={hostname:HOST,port:PORT,path:PATH,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(p),"X-Server-Code":CODE,"X-Server-Key":KEY},timeout:8000,rejectUnauthorized:false};const q=https.request(o,res=>{let b="";res.on("data",c=>b+=c);res.on("end",()=>r(res.statusCode===200))});q.on("error",()=>r(false));q.on("timeout",()=>{q.destroy();r(false)});q.write(p);q.end()})} (async()=>{const d={server_code:CODE,server_name:NAME,timestamp:new Date().toISOString(),hardware:hw()};const ok=await post(d);console.log(new Date().toISOString()+" "+(ok?"OK":"FAIL"))})(); `.trim(); }