添加鉴权逻辑
This commit is contained in:
@@ -178,10 +178,12 @@ async function getOverviewMetrics(url, sourceName) {
|
||||
// Build per-instance data map
|
||||
const instances = new Map();
|
||||
|
||||
const getOrCreate = (instance) => {
|
||||
if (!instances.has(instance)) {
|
||||
instances.set(instance, {
|
||||
instance,
|
||||
const getOrCreate = (metric) => {
|
||||
const key = metric.instance;
|
||||
if (!instances.has(key)) {
|
||||
instances.set(key, {
|
||||
instance: key,
|
||||
job: metric.job || 'Unknown',
|
||||
source: sourceName,
|
||||
cpuPercent: 0,
|
||||
cpuCores: 0,
|
||||
@@ -194,54 +196,54 @@ async function getOverviewMetrics(url, sourceName) {
|
||||
up: false
|
||||
});
|
||||
}
|
||||
return instances.get(instance);
|
||||
return instances.get(key);
|
||||
};
|
||||
|
||||
// Parse UP status
|
||||
for (const r of upResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.up = parseFloat(r.value[1]) === 1;
|
||||
}
|
||||
|
||||
// Parse CPU usage
|
||||
for (const r of cpuResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.cpuPercent = parseFloat(r.value[1]) || 0;
|
||||
}
|
||||
|
||||
// Parse CPU count
|
||||
for (const r of cpuCountResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.cpuCores = parseFloat(r.value[1]) || 0;
|
||||
}
|
||||
|
||||
// Parse memory
|
||||
for (const r of memTotalResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.memTotal = parseFloat(r.value[1]) || 0;
|
||||
}
|
||||
for (const r of memAvailResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.memUsed = inst.memTotal - (parseFloat(r.value[1]) || 0);
|
||||
}
|
||||
|
||||
// Parse disk
|
||||
for (const r of diskTotalResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.diskTotal = parseFloat(r.value[1]) || 0;
|
||||
}
|
||||
for (const r of diskFreeResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.diskUsed = inst.diskTotal - (parseFloat(r.value[1]) || 0);
|
||||
}
|
||||
|
||||
// Parse network rates
|
||||
for (const r of netRxResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.netRx = parseFloat(r.value[1]) || 0;
|
||||
}
|
||||
for (const r of netTxResult) {
|
||||
const inst = getOrCreate(r.metric.instance);
|
||||
const inst = getOrCreate(r.metric);
|
||||
inst.netTx = parseFloat(r.value[1]) || 0;
|
||||
}
|
||||
|
||||
@@ -290,7 +292,8 @@ async function getOverviewMetrics(url, sourceName) {
|
||||
},
|
||||
network: {
|
||||
rx: totalNetRx,
|
||||
tx: totalNetTx
|
||||
tx: totalNetTx,
|
||||
total: totalNetRx + totalNetTx
|
||||
},
|
||||
traffic24h: {
|
||||
rx: totalTraffic24hRx,
|
||||
|
||||
Reference in New Issue
Block a user