优化时间范围选择

This commit is contained in:
CN-JS-HuiBai
2026-04-04 22:27:35 +08:00
parent 4f04227976
commit 75736c0c4c
6 changed files with 662 additions and 68 deletions

View File

@@ -626,6 +626,26 @@ app.get('/api/metrics/server-details', async (req, res) => {
}
});
// Get historical metrics for a specific server
app.get('/api/metrics/server-history', async (req, res) => {
const { instance, job, source, metric, range, start, end } = req.query;
if (!instance || !job || !source || !metric) {
return res.status(400).json({ error: 'instance, job, source, and metric are required' });
}
try {
const [rows] = await db.query('SELECT url FROM prometheus_sources WHERE name = ?', [source]);
if (rows.length === 0) return res.status(404).json({ error: 'Source not found' });
const sourceUrl = rows[0].url;
const data = await prometheusService.getServerHistory(sourceUrl, instance, job, metric, range, start, end);
res.json(data);
} catch (err) {
res.status(500).json({ error: err.message });
}
});
// SPA fallback
app.get('*', (req, res, next) => {
if (req.path.startsWith('/api/') || req.path.includes('.')) return next();