优化时间范围选择
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user