添加刷新按钮

This commit is contained in:
CN-JS-HuiBai
2026-04-06 23:13:50 +08:00
parent 1bfee2026f
commit c94b697319
4 changed files with 55 additions and 10 deletions

View File

@@ -663,7 +663,7 @@ app.post('/api/settings', requireAuth, async (req, res) => {
// ==================== Metrics Aggregation ====================
// Reusable function to get overview metrics
async function getOverview() {
async function getOverview(force = false) {
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"');
if (sources.length === 0) {
return {
@@ -680,8 +680,12 @@ async function getOverview() {
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;
if (force) {
await cache.del(cacheKey);
} else {
const cached = await cache.get(cacheKey);
if (cached) return cached;
}
try {
const metrics = await prometheusService.getOverviewMetrics(source.url, source.name);
@@ -790,7 +794,8 @@ async function getOverview() {
// Get all aggregated metrics from all Prometheus sources
app.get('/api/metrics/overview', async (req, res) => {
try {
const overview = await getOverview();
const force = req.query.force === 'true';
const overview = await getOverview(force);
res.json(overview);
} catch (err) {
console.error('Error fetching overview metrics:', err);
@@ -801,9 +806,15 @@ app.get('/api/metrics/overview', async (req, res) => {
// Get network traffic history (past 24h) from Prometheus
app.get('/api/metrics/network-history', async (req, res) => {
try {
const force = req.query.force === 'true';
const cacheKey = 'network_history_all';
const cached = await cache.get(cacheKey);
if (cached) return res.json(cached);
if (force) {
await cache.del(cacheKey);
} else {
const cached = await cache.get(cacheKey);
if (cached) return res.json(cached);
}
const [sources] = await db.query('SELECT * FROM prometheus_sources WHERE is_server_source = 1 AND type != "blackbox"');
if (sources.length === 0) {