修复地区查询错误的BUG
This commit is contained in:
@@ -617,22 +617,17 @@ app.get('/api/metrics/overview', async (req, res) => {
|
|||||||
|
|
||||||
// --- Add Geo Information to Servers ---
|
// --- Add Geo Information to Servers ---
|
||||||
const geoServers = await Promise.all(overview.servers.map(async (server) => {
|
const geoServers = await Promise.all(overview.servers.map(async (server) => {
|
||||||
const realInstance = prometheusService.resolveToken(server.instance);
|
// Use originalInstance if available for correct location lookup
|
||||||
|
const realInstance = server.originalInstance || prometheusService.resolveToken(server.instance);
|
||||||
const cleanIp = realInstance.split(':')[0];
|
const cleanIp = realInstance.split(':')[0];
|
||||||
|
|
||||||
|
let geoData = null;
|
||||||
|
|
||||||
// Try to get from DB cache only (fast)
|
// Try to get from DB cache only (fast)
|
||||||
try {
|
try {
|
||||||
const [rows] = await db.query('SELECT * FROM server_locations WHERE ip = ?', [cleanIp]);
|
const [rows] = await db.query('SELECT * FROM server_locations WHERE ip = ?', [cleanIp]);
|
||||||
if (rows.length > 0) {
|
if (rows.length > 0) {
|
||||||
const location = rows[0];
|
geoData = rows[0];
|
||||||
return {
|
|
||||||
...server,
|
|
||||||
country: location.country,
|
|
||||||
countryName: location.country_name,
|
|
||||||
city: location.city,
|
|
||||||
lat: location.latitude,
|
|
||||||
lng: location.longitude
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
// Trigger background resolution for future requests
|
// Trigger background resolution for future requests
|
||||||
geoService.getLocation(cleanIp).catch(() => {});
|
geoService.getLocation(cleanIp).catch(() => {});
|
||||||
@@ -640,7 +635,21 @@ app.get('/api/metrics/overview', async (req, res) => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// DB error, skip geo for now
|
// DB error, skip geo for now
|
||||||
}
|
}
|
||||||
return server;
|
|
||||||
|
// Prepare the server object without sensitive originalInstance
|
||||||
|
const { originalInstance, ...safeServer } = server;
|
||||||
|
|
||||||
|
if (geoData) {
|
||||||
|
return {
|
||||||
|
...safeServer,
|
||||||
|
country: geoData.country,
|
||||||
|
countryName: geoData.country_name,
|
||||||
|
city: geoData.city,
|
||||||
|
lat: geoData.latitude,
|
||||||
|
lng: geoData.longitude
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return safeServer;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
overview.servers = geoServers;
|
overview.servers = geoServers;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const httpAgent = new http.Agent({ keepAlive: true });
|
|||||||
const httpsAgent = new https.Agent({ keepAlive: true, rejectUnauthorized: false });
|
const httpsAgent = new https.Agent({ keepAlive: true, rejectUnauthorized: false });
|
||||||
|
|
||||||
const serverIdMap = new Map(); // token -> { instance, job, source }
|
const serverIdMap = new Map(); // token -> { instance, job, source }
|
||||||
const SECRET = crypto.randomBytes(16).toString('hex');
|
const SECRET = process.env.APP_SECRET || 'prom-data-panel-stable-secret-key-123';
|
||||||
|
|
||||||
function getServerToken(instance, job, source) {
|
function getServerToken(instance, job, source) {
|
||||||
const hash = crypto.createHmac('sha256', SECRET)
|
const hash = crypto.createHmac('sha256', SECRET)
|
||||||
@@ -363,10 +363,7 @@ async function getOverviewMetrics(url, sourceName) {
|
|||||||
tx: totalTraffic24hTx,
|
tx: totalTraffic24hTx,
|
||||||
total: totalTraffic24hRx + totalTraffic24hTx
|
total: totalTraffic24hRx + totalTraffic24hTx
|
||||||
},
|
},
|
||||||
servers: allInstancesList.map(s => {
|
servers: allInstancesList
|
||||||
const { originalInstance, ...rest } = s;
|
|
||||||
return rest;
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user