优化显示
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user