优化后端的性能

This commit is contained in:
CN-JS-HuiBai
2026-04-24 15:46:21 +08:00
parent c254923bd6
commit 8e50437ed4
5 changed files with 126 additions and 63 deletions

View File

@@ -1,12 +1,15 @@
const axios = require('axios');
const http = require('http');
const https = require('https');
const cache = require('./cache'); // <-- ADD
const cache = require('./cache');
const crypto = require('crypto');
const QUERY_TIMEOUT = 10000;
// Reusable agents to handle potential redirect issues and protocol mismatches
const crypto = require('crypto');
function getCacheKey(type, baseUrl, expr, extra = '') {
return `prom_${type}:${crypto.createHash('md5').update(`${baseUrl}:${expr}:${extra}`).digest('hex')}`;
}
const httpAgent = new http.Agent({ keepAlive: true });
const httpsAgent = new https.Agent({ keepAlive: true });
@@ -951,5 +954,6 @@ module.exports = {
console.error(`[Prometheus] Error fetching latency for ${target}:`, err.message);
return null;
}
}
},
getCacheKey
};