From 65eae5574f6b9eae3a77b5b3a34953aaf32ecf60 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Sat, 4 Apr 2026 18:17:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/app.js | 1 - server/prometheus-service.js | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index e3535e7..6dca5af 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -328,7 +328,6 @@
${escapeHtml(server.job)}
-
${escapeHtml(server.instance)}
${escapeHtml(server.source)} diff --git a/server/prometheus-service.js b/server/prometheus-service.js index 8557e44..90547dc 100644 --- a/server/prometheus-service.js +++ b/server/prometheus-service.js @@ -42,18 +42,18 @@ async function testConnection(url) { // Using native fetch to avoid follow-redirects/axios "protocol mismatch" issues in some Node environments const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), QUERY_TIMEOUT); - + // Node native fetch - handles http/https automatically const res = await fetch(`${normalized}/api/v1/status/buildinfo`, { signal: controller.signal }); - + clearTimeout(timer); if (!res.ok) { throw new Error(`Prometheus returned HTTP ${res.status}`); } - + const data = await res.json(); return data?.data?.version || 'unknown'; } catch (err) { @@ -74,17 +74,17 @@ async function query(baseUrl, expr) { const params = new URLSearchParams({ query: expr }); const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), QUERY_TIMEOUT); - + const res = await fetch(`${url}/api/v1/query?${params.toString()}`, { signal: controller.signal }); - + clearTimeout(timer); if (!res.ok) { throw new Error(`Prometheus returned HTTP ${res.status}`); } - + const data = await res.json(); if (data.status !== 'success') { throw new Error(`Prometheus query failed: ${data.error || 'unknown error'}`); @@ -107,17 +107,17 @@ async function queryRange(baseUrl, expr, start, end, step) { const params = new URLSearchParams({ query: expr, start, end, step }); const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), QUERY_TIMEOUT); - + const res = await fetch(`${url}/api/v1/query_range?${params.toString()}`, { signal: controller.signal }); - + clearTimeout(timer); if (!res.ok) { throw new Error(`Prometheus returned HTTP ${res.status}`); } - + const data = await res.json(); if (data.status !== 'success') { throw new Error(`Prometheus range query failed: ${data.error || 'unknown error'}`); @@ -180,6 +180,7 @@ async function getOverviewMetrics(url, sourceName) { const getOrCreate = (metric) => { const key = metric.instance; + if (!instances.has(key)) { instances.set(key, { instance: key,