修复数据源统计问题

This commit is contained in:
CN-JS-HuiBai
2026-04-06 02:13:41 +08:00
parent 607d71d1ca
commit 9845f2fe5c
2 changed files with 13 additions and 9 deletions

View File

@@ -1865,11 +1865,12 @@
if (dom.sourceFilter) {
const current = dom.sourceFilter.value;
let html = '<option value="all">所有数据源</option>';
sources.forEach(source => {
const displaySources = sources.filter(s => s.type !== 'blackbox');
displaySources.forEach(source => {
html += `<option value="${escapeHtml(source.name)}">${escapeHtml(source.name)}</option>`;
});
dom.sourceFilter.innerHTML = html;
if (sources.some(s => s.name === current)) {
if (displaySources.some(s => s.name === current)) {
dom.sourceFilter.value = current;
} else {
dom.sourceFilter.value = 'all';
@@ -1889,9 +1890,11 @@
try {
const response = await fetch('/api/sources');
const sources = await response.json();
if (dom.totalServersLabel) dom.totalServersLabel.textContent = `服务器总数 (${sources.length} 数据源)`;
updateSourceFilterOptions(sources);
renderSources(sources);
const sourcesArray = Array.isArray(sources) ? sources : [];
const promSources = sourcesArray.filter(s => s.type !== 'blackbox');
if (dom.totalServersLabel) dom.totalServersLabel.textContent = `服务器总数 (${promSources.length} 数据源)`;
updateSourceFilterOptions(sourcesArray);
renderSources(sourcesArray);
} catch (err) {
console.error('Error loading sources:', err);
}
@@ -2061,7 +2064,8 @@
const response = await fetch('/api/sources');
const sources = await response.json();
const sourcesArray = Array.isArray(sources) ? sources : [];
if (dom.totalServersLabel) dom.totalServersLabel.textContent = `服务器总数 (${sourcesArray.length} 数据源)`;
const promSources = sourcesArray.filter(s => s.type !== 'blackbox');
if (dom.totalServersLabel) dom.totalServersLabel.textContent = `服务器总数 (${promSources.length} 数据源)`;
updateSourceFilterOptions(sourcesArray);
} catch (err) {
// ignore

View File

@@ -610,7 +610,7 @@ app.post('/api/settings', requireAuth, async (req, res) => {
// Reusable function to get overview metrics
async function getOverview() {
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1');
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"');
if (sources.length === 0) {
return {
totalServers: 0,
@@ -751,7 +751,7 @@ app.get('/api/metrics/network-history', async (req, res) => {
const cached = await cache.get(cacheKey);
if (cached) return res.json(cached);
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1');
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"');
if (sources.length === 0) {
return res.json({ timestamps: [], rx: [], tx: [] });
}
@@ -780,7 +780,7 @@ app.get('/api/metrics/network-history', async (req, res) => {
// Get CPU usage history for sparklines
app.get('/api/metrics/cpu-history', async (req, res) => {
try {
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1');
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"');
if (sources.length === 0) {
return res.json({ timestamps: [], values: [] });
}