优化数据库稳定性
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user