优化数据库稳定性

This commit is contained in:
CN-JS-HuiBai
2026-04-11 18:14:04 +08:00
parent a876c854f4
commit d7ac1bedb4
3 changed files with 79 additions and 26 deletions

View File

@@ -876,10 +876,8 @@ module.exports = {
getLatency: async (blackboxUrl, target) => {
if (!blackboxUrl || !target) return null;
try {
const normalized = blackboxUrl.trim().replace(/\/+$/, '');
const normalized = normalizeUrl(blackboxUrl);
// Construct a single optimized query searching for priority metrics and common labels
// Prioritize probe_icmp_duration_seconds OVER probe_duration_seconds
const queryExpr = `(
probe_icmp_duration_seconds{phase="rtt", instance="${target}"} or
probe_icmp_duration_seconds{phase="rtt", target="${target}"} or
@@ -891,14 +889,9 @@ module.exports = {
probe_duration_seconds{target="${target}"}
)`;
const params = new URLSearchParams({ query: queryExpr });
const res = await fetch(`${normalized}/api/v1/query?${params.toString()}`);
if (res.ok) {
const data = await res.json();
if (data.status === 'success' && data.data.result.length > 0) {
return parseFloat(data.data.result[0].value[1]) * 1000;
}
const result = await query(normalized, queryExpr);
if (result && result.length > 0) {
return parseFloat(result[0].value[1]) * 1000;
}
return null;
} catch (err) {