feat: 哪吒探针网络监控接口支持用参数传入检测次数; 节点字段上自定义的多个次数, 只取最大值

This commit is contained in:
xream 2024-04-19 06:27:45 +08:00
parent 4819ae95e4
commit c7329c32eb
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9

View File

@ -176,7 +176,11 @@ async function downloadSubscription(req, res) {
nezhaIndex = /^\d+$/.test(nezhaIndex)
? parseInt(nezhaIndex, 10)
: output.findIndex((i) => i.name === nezhaIndex);
output = await nezhaMonitor(output[nezhaIndex], nezhaIndex);
output = await nezhaMonitor(
output[nezhaIndex],
nezhaIndex,
req.query,
);
}
res.set('Content-Type', 'application/json;charset=utf-8').send(
output,
@ -327,7 +331,11 @@ async function downloadCollection(req, res) {
nezhaIndex = /^\d+$/.test(nezhaIndex)
? parseInt(nezhaIndex, 10)
: output.findIndex((i) => i.name === nezhaIndex);
output = await nezhaMonitor(output[nezhaIndex], nezhaIndex);
output = await nezhaMonitor(
output[nezhaIndex],
nezhaIndex,
req.query,
);
}
res.set('Content-Type', 'application/json;charset=utf-8').send(
output,
@ -366,7 +374,7 @@ async function downloadCollection(req, res) {
}
}
async function nezhaMonitor(proxy, index) {
async function nezhaMonitor(proxy, index, query) {
const result = {
code: 0,
message: 'success',
@ -395,7 +403,8 @@ async function nezhaMonitor(proxy, index) {
timeout: 2000,
},
];
const number =
query.number || Math.max(...monitors.map((i) => i.number)) || 3;
for (const monitor of monitors) {
const interval = 10 * 60 * 1000;
const data = {
@ -406,8 +415,7 @@ async function nezhaMonitor(proxy, index) {
created_at: [],
avg_delay: [],
};
for (let index = 0; index < monitor.number; index++) {
for (let index = 0; index < number; index++) {
const startedAt = Date.now();
try {
await $.http[(monitor.method || 'HEAD').toLowerCase()]({