修复BUG
This commit is contained in:
@@ -31,23 +31,33 @@ async function pollLatency() {
|
||||
|
||||
const startTime = Date.now();
|
||||
const response = await axios.get(probeUrl, { timeout: 5000 });
|
||||
const duration = (Date.now() - startTime) / 1000; // Fallback to local timing if parsing fails
|
||||
|
||||
// Parse prometheus text format for probe_duration_seconds
|
||||
// 1. Parse prometheus text format for success and specific metrics
|
||||
let latency = null;
|
||||
let success = false;
|
||||
const lines = response.data.split('\n');
|
||||
|
||||
for (const line of lines) {
|
||||
// Match "probe_duration_seconds 0.123" or "probe_duration_seconds{...} 0.123"
|
||||
const match = line.match(/^probe_duration_seconds(?:\{.*\})?\s+([\d.]+)/);
|
||||
if (match) {
|
||||
latency = parseFloat(match[1]) * 1000; // to ms
|
||||
if (line.match(/^probe_success\s+1/)) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (latency === null) {
|
||||
// Fallback to local response time if metric not found in output
|
||||
latency = duration * 1000;
|
||||
if (success) {
|
||||
// Try specialized metrics first for better accuracy
|
||||
const priorityMetrics = ['probe_icmp_duration_seconds', 'probe_http_duration_seconds', 'probe_duration_seconds'];
|
||||
for (const metricName of priorityMetrics) {
|
||||
const regex = new RegExp(`^${metricName}(?:\\{.*\\})?\\s+([\\d.]+)`);
|
||||
for (const line of lines) {
|
||||
const match = line.match(regex);
|
||||
if (match) {
|
||||
latency = parseFloat(match[1]) * 1000; // to ms
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (latency !== null) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Save to Valkey
|
||||
|
||||
Reference in New Issue
Block a user