Skip to content

Commit

Permalink
feat: 健康探针
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Oct 19, 2024
1 parent 533a5c9 commit 0768f30
Show file tree
Hide file tree
Showing 5 changed files with 635 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=
# 自动点赞用户id(只有在cron_bypassCF_likeUser有用,也就是自动点赞特定用户的时候有用)
SPECIFIC_USER=14790897
# 健康探针端口
HEALTH_PORT=8081
33 changes: 33 additions & 0 deletions bypasscf.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,36 @@ async function takeScreenshots(page) {
}
});
}
import express from "express";

const healthApp = express();
const HEALTH_PORT = process.env.HEALTH_PORT || 8081;

// 健康探针路由
healthApp.get("/health", (req, res) => {
const memoryUsage = process.memoryUsage();

// 将字节转换为MB
const memoryUsageMB = {
rss: (memoryUsage.rss / (1024 * 1024)).toFixed(2), // 转换为MB并保留两位小数
heapTotal: (memoryUsage.heapTotal / (1024 * 1024)).toFixed(2),
heapUsed: (memoryUsage.heapUsed / (1024 * 1024)).toFixed(2),
external: (memoryUsage.external / (1024 * 1024)).toFixed(2),
arrayBuffers: (memoryUsage.arrayBuffers / (1024 * 1024)).toFixed(2),
};

const healthData = {
status: "OK",
timestamp: new Date().toISOString(),
memoryUsage: memoryUsageMB,
uptime: process.uptime().toFixed(2), // 保留两位小数
};

res.status(200).json(healthData);
});

healthApp.listen(HEALTH_PORT, () => {
console.log(
`Health check endpoint is running at http://localhost:${HEALTH_PORT}/health`
);
});
41 changes: 37 additions & 4 deletions bypasscf_likeUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import TelegramBot from "node-telegram-bot-api";
dotenv.config();

// 截图保存的文件夹
const screenshotDir = "screenshots";
if (!fs.existsSync(screenshotDir)) {
fs.mkdirSync(screenshotDir);
}
// const screenshotDir = "screenshots";
// if (!fs.existsSync(screenshotDir)) {
// fs.mkdirSync(screenshotDir);
// }
puppeteer.use(StealthPlugin());

// Load the default .env file
Expand Down Expand Up @@ -406,3 +406,36 @@ async function takeScreenshots(page) {
}
});
}
import express from "express";

const healthApp = express();
const HEALTH_PORT = process.env.HEALTH_PORT || 8081;

// 健康探针路由
healthApp.get("/health", (req, res) => {
const memoryUsage = process.memoryUsage();

// 将字节转换为MB
const memoryUsageMB = {
rss: (memoryUsage.rss / (1024 * 1024)).toFixed(2), // 转换为MB并保留两位小数
heapTotal: (memoryUsage.heapTotal / (1024 * 1024)).toFixed(2),
heapUsed: (memoryUsage.heapUsed / (1024 * 1024)).toFixed(2),
external: (memoryUsage.external / (1024 * 1024)).toFixed(2),
arrayBuffers: (memoryUsage.arrayBuffers / (1024 * 1024)).toFixed(2),
};

const healthData = {
status: "OK",
timestamp: new Date().toISOString(),
memoryUsage: memoryUsageMB,
uptime: process.uptime().toFixed(2), // 保留两位小数
};

res.status(200).json(healthData);
});

healthApp.listen(HEALTH_PORT, () => {
console.log(
`Health check endpoint is running at http://localhost:${HEALTH_PORT}/health`
);
});
Loading

0 comments on commit 0768f30

Please sign in to comment.