添加valkey support

This commit is contained in:
CN-JS-HuiBai
2026-04-04 19:33:22 +08:00
parent 96dd30a343
commit f75e755f3d
6 changed files with 184 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ const cors = require('cors');
const path = require('path');
const db = require('./db');
const prometheusService = require('./prometheus-service');
const cache = require('./cache');
const checkAndFixDatabase = require('./db-integrity-check');
const app = express();
@@ -462,12 +463,20 @@ app.get('/api/metrics/overview', async (req, res) => {
});
}
const allMetrics = await Promise.all(sources.map(source =>
prometheusService.getOverviewMetrics(source.url, source.name).catch(err => {
const allMetrics = await Promise.all(sources.map(async (source) => {
const cacheKey = `source_metrics:${source.url}:${source.name}`;
const cached = await cache.get(cacheKey);
if (cached) return cached;
try {
const metrics = await prometheusService.getOverviewMetrics(source.url, source.name);
await cache.set(cacheKey, metrics, 15); // Cache for 15s
return metrics;
} catch (err) {
console.error(`Error fetching metrics from ${source.name}:`, err.message);
return null;
})
));
}
}));
const validMetrics = allMetrics.filter(m => m !== null);