修复延迟检测错误
This commit is contained in:
@@ -48,7 +48,8 @@ async function pollLatency() {
|
|||||||
// Try specialized metrics first for better accuracy
|
// Try specialized metrics first for better accuracy
|
||||||
const priorityMetrics = ['probe_icmp_duration_seconds', 'probe_http_duration_seconds', 'probe_duration_seconds'];
|
const priorityMetrics = ['probe_icmp_duration_seconds', 'probe_http_duration_seconds', 'probe_duration_seconds'];
|
||||||
for (const metricName of priorityMetrics) {
|
for (const metricName of priorityMetrics) {
|
||||||
const regex = new RegExp(`^${metricName}(?:\\{.*\\})?\\s+([\\d.]+)`);
|
// Support scientific notation (e.g. 1.23e-04)
|
||||||
|
const regex = new RegExp(`^${metricName}(?:\\{.*\\})?\\s+([\\d.eE+-]+)`);
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
const match = line.match(regex);
|
const match = line.match(regex);
|
||||||
if (match) {
|
if (match) {
|
||||||
|
|||||||
@@ -805,12 +805,26 @@ module.exports = {
|
|||||||
if (!blackboxUrl || !target) return null;
|
if (!blackboxUrl || !target) return null;
|
||||||
try {
|
try {
|
||||||
const normalized = blackboxUrl.trim().replace(/\/+$/, '');
|
const normalized = blackboxUrl.trim().replace(/\/+$/, '');
|
||||||
const params = new URLSearchParams({ query: `probe_duration_seconds{instance_name="${target}"}` });
|
|
||||||
|
// 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{instance="${target}"} or
|
||||||
|
probe_icmp_duration_seconds{target="${target}"} or
|
||||||
|
probe_icmp_duration_seconds{instance_name="${target}"} or
|
||||||
|
probe_duration_seconds{instance="${target}"} or
|
||||||
|
probe_duration_seconds{target="${target}"} or
|
||||||
|
probe_duration_seconds{instance_name="${target}"}
|
||||||
|
)`;
|
||||||
|
|
||||||
|
const params = new URLSearchParams({ query: queryExpr });
|
||||||
const res = await fetch(`${normalized}/api/v1/query?${params.toString()}`);
|
const res = await fetch(`${normalized}/api/v1/query?${params.toString()}`);
|
||||||
if (!res.ok) return null;
|
|
||||||
const data = await res.json();
|
if (res.ok) {
|
||||||
if (data.status === 'success' && data.data.result.length > 0) {
|
const data = await res.json();
|
||||||
return parseFloat(data.data.result[0].value[1]) * 1000;
|
if (data.status === 'success' && data.data.result.length > 0) {
|
||||||
|
return parseFloat(data.data.result[0].value[1]) * 1000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user