修复数据统计错误的问题
This commit is contained in:
@@ -2070,6 +2070,18 @@
|
|||||||
const savedTheme = localStorage.getItem('theme');
|
const savedTheme = localStorage.getItem('theme');
|
||||||
const themeToApply = savedTheme || settings.default_theme || 'dark';
|
const themeToApply = savedTheme || settings.default_theme || 'dark';
|
||||||
applyTheme(themeToApply);
|
applyTheme(themeToApply);
|
||||||
|
|
||||||
|
// Apply settings to UI (logo, name, etc.)
|
||||||
|
applySiteSettings(window.SITE_SETTINGS);
|
||||||
|
|
||||||
|
// Refresh overview and historical charts to reflect new source selections
|
||||||
|
fetchNetworkHistory(true);
|
||||||
|
// We can't force the WS broadcast easily from client,
|
||||||
|
// but we can fetch the overview via REST API once to update UI
|
||||||
|
fetch('/api/metrics/overview?force=true')
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => updateDashboard(data))
|
||||||
|
.catch(() => {});
|
||||||
} else {
|
} else {
|
||||||
const err = await response.json();
|
const err = await response.json();
|
||||||
showSiteMessage(`保存失败: ${err.error || '未知错误'}`, 'error');
|
showSiteMessage(`保存失败: ${err.error || '未知错误'}`, 'error');
|
||||||
|
|||||||
@@ -964,7 +964,21 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
|||||||
|
|
||||||
// Reusable function to get overview metrics
|
// Reusable function to get overview metrics
|
||||||
async function getOverview(force = false) {
|
async function getOverview(force = false) {
|
||||||
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"');
|
const [settingsRows] = await db.query('SELECT network_data_sources FROM site_settings WHERE id = 1');
|
||||||
|
const selectedSourcesStr = settingsRows.length > 0 ? settingsRows[0].network_data_sources : null;
|
||||||
|
|
||||||
|
let query = 'SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"';
|
||||||
|
let params = [];
|
||||||
|
|
||||||
|
if (selectedSourcesStr) {
|
||||||
|
const selectedSourceNames = selectedSourcesStr.split(',').map(s => s.trim()).filter(s => s);
|
||||||
|
if (selectedSourceNames.length > 0) {
|
||||||
|
query += ' AND name IN (?)';
|
||||||
|
params.push(selectedSourceNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [sources] = await db.query(query, params);
|
||||||
if (sources.length === 0) {
|
if (sources.length === 0) {
|
||||||
return {
|
return {
|
||||||
totalServers: 0,
|
totalServers: 0,
|
||||||
@@ -1159,7 +1173,21 @@ app.get('/api/metrics/network-history', async (req, res) => {
|
|||||||
// Get CPU usage history for sparklines
|
// Get CPU usage history for sparklines
|
||||||
app.get('/api/metrics/cpu-history', async (req, res) => {
|
app.get('/api/metrics/cpu-history', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"');
|
const [settingsRows] = await db.query('SELECT network_data_sources FROM site_settings WHERE id = 1');
|
||||||
|
const selectedSourcesStr = settingsRows.length > 0 ? settingsRows[0].network_data_sources : null;
|
||||||
|
|
||||||
|
let query = 'SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"';
|
||||||
|
let params = [];
|
||||||
|
|
||||||
|
if (selectedSourcesStr) {
|
||||||
|
const selectedSourceNames = selectedSourcesStr.split(',').map(s => s.trim()).filter(s => s);
|
||||||
|
if (selectedSourceNames.length > 0) {
|
||||||
|
query += ' AND name IN (?)';
|
||||||
|
params.push(selectedSourceNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [sources] = await db.query(query, params);
|
||||||
if (sources.length === 0) {
|
if (sources.length === 0) {
|
||||||
return res.json({ timestamps: [], values: [] });
|
return res.json({ timestamps: [], values: [] });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user