添加更详细的信息查询

This commit is contained in:
CN-JS-HuiBai
2026-04-04 22:05:53 +08:00
parent d0bd05409d
commit ba712f1907
5 changed files with 244 additions and 3 deletions

View File

@@ -601,6 +601,31 @@ app.get('/api/metrics/cpu-history', async (req, res) => {
}
});
// Get detailed metrics for a specific server
app.get('/api/metrics/server-details', async (req, res) => {
const { instance, job, source } = req.query;
if (!instance || !job || !source) {
return res.status(400).json({ error: 'instance, job, and source name are required' });
}
try {
// Find the source URL by name
const [rows] = await db.query('SELECT url FROM prometheus_sources WHERE name = ?', [source]);
if (rows.length === 0) {
return res.status(404).json({ error: 'Prometheus source not found' });
}
const sourceUrl = rows[0].url;
// Fetch detailed metrics
const details = await prometheusService.getServerDetails(sourceUrl, instance, job);
res.json(details);
} catch (err) {
console.error(`Error fetching server details for ${instance}:`, err.message);
res.status(500).json({ error: 'Failed to fetch server details' });
}
});
// SPA fallback
app.get('*', (req, res, next) => {
if (req.path.startsWith('/api/') || req.path.includes('.')) return next();