fix: push-heartbeat 走nginx 80端口 /console/api/heartbeat 非直连3920
This commit is contained in:
parent
ef0f056702
commit
56db2394d4
@ -13,8 +13,9 @@ const SERVERS = [
|
||||
{ code: "BS-SH-005", name: "上海·国内节点", ip: "124.223.10.33", key: "zy_gtw_b1045de5ddfd7832e3c53349d9c896f054b85a4a9ece22f9", port: 3910 },
|
||||
];
|
||||
|
||||
const MASTER = "43.139.217.141";
|
||||
const MASTER_PORT = 3920;
|
||||
const MASTER_HOST = "43.139.217.141";
|
||||
const MASTER_PORT = 80;
|
||||
const MASTER_PATH = "/console/api/heartbeat";
|
||||
|
||||
function gkExec(srv, cmd, timeoutMs) {
|
||||
timeoutMs = timeoutMs || 10000;
|
||||
@ -35,13 +36,13 @@ function gkExec(srv, cmd, timeoutMs) {
|
||||
});
|
||||
}
|
||||
|
||||
// 推送脚本模板(内联,避免文件传输)
|
||||
// 推送脚本模板 — 通过nginx /console/ → console-server:3920
|
||||
function pushScript(code, name, key) {
|
||||
return `
|
||||
const http=require("http"),os=require("os");
|
||||
const MASTER="${MASTER}",PORT=${MASTER_PORT},CODE="${code}",NAME="${name}",KEY="${key}";
|
||||
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:MASTER,port:PORT,path:"/api/heartbeat",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};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()})}
|
||||
(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();
|
||||
}
|
||||
@ -72,7 +73,7 @@ async function deployOne(srv) {
|
||||
|
||||
async function main() {
|
||||
console.log('铸渊 · push-heartbeat 批量部署');
|
||||
console.log(`主控台: ${MASTER}:${MASTER_PORT}`);
|
||||
console.log(`主控台: ${MASTER_HOST}:${MASTER_PORT}${MASTER_PATH}`);
|
||||
console.log(`目标: ${SERVERS.length}台远程服务器\n`);
|
||||
|
||||
let ok = 0, fail = 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user