修改采集逻辑
This commit is contained in:
@@ -559,9 +559,7 @@ async function getServerDetails(baseUrl, instance, job) {
|
||||
sockstatTcpMem: `node_sockstat_TCP_mem{instance="${node}",job="${job}"} * 4096`,
|
||||
// Get individual partitions (excluding virtual and FUSE mounts)
|
||||
partitions_size: `node_filesystem_size_bytes{instance="${node}", job="${job}", fstype!~"tmpfs|autofs|proc|sysfs|fuse.*", mountpoint!~"/tmp.*|/var/lib/docker/.*|/run/.*"}`,
|
||||
partitions_free: `node_filesystem_free_bytes{instance="${node}", job="${job}", fstype!~"tmpfs|autofs|proc|sysfs|fuse.*", mountpoint!~"/tmp.*|/var/lib/docker/.*|/run/.*"}`,
|
||||
ipv4: `node_network_address_info{instance="${node}", job="${job}", address!~"127\\\\..*|10\\\\..*|172\\\\.(1[6-9]|2[0-9]|3[0-1])\\\\..*|192\\\\.168\\\\..*", address=~"\\\\d+\\\\.\\\\d+\\\\.\\\\d+\\\\.\\\\d+"}`,
|
||||
ipv6: `node_network_address_info{instance="${node}", job="${job}", address=~".*:.*", address!~"fe80:.*|::1"}`
|
||||
partitions_free: `node_filesystem_free_bytes{instance="${node}", job="${job}", fstype!~"tmpfs|autofs|proc|sysfs|fuse.*", mountpoint!~"/tmp.*|/var/lib/docker/.*|/run/.*"}`
|
||||
};
|
||||
|
||||
const results = {};
|
||||
@@ -573,8 +571,6 @@ async function getServerDetails(baseUrl, instance, job) {
|
||||
mountpoint: r.metric.mountpoint,
|
||||
value: parseFloat(r.value[1]) || 0
|
||||
}));
|
||||
} else if (key === 'ipv4' || key === 'ipv6') {
|
||||
results[key] = res.map(r => r.metric.address).filter(a => a);
|
||||
} else {
|
||||
results[key] = res.length > 0 ? parseFloat(res[0].value[1]) : 0;
|
||||
}
|
||||
@@ -586,6 +582,39 @@ async function getServerDetails(baseUrl, instance, job) {
|
||||
|
||||
await Promise.all(queryPromises);
|
||||
|
||||
// Add IP information from Prometheus target (discovered labels or scrape URL)
|
||||
try {
|
||||
const targets = await getTargets(baseUrl);
|
||||
const matchedTarget = targets.find(t => t.labels && t.labels.instance === node && t.labels.job === job);
|
||||
if (matchedTarget) {
|
||||
// Extract address from scrapeUrl or instance label
|
||||
const scrapeUrl = matchedTarget.scrapeUrl || '';
|
||||
try {
|
||||
const urlObj = new URL(scrapeUrl);
|
||||
const host = urlObj.hostname;
|
||||
if (host.includes(':')) {
|
||||
results.ipv6 = [host];
|
||||
results.ipv4 = [];
|
||||
} else {
|
||||
results.ipv4 = [host];
|
||||
results.ipv6 = [];
|
||||
}
|
||||
} catch (e) {
|
||||
// Fallback to instance label without port
|
||||
const inst = matchedTarget.labels.instance.split(':')[0];
|
||||
results.ipv4 = [inst];
|
||||
results.ipv6 = [];
|
||||
}
|
||||
} else {
|
||||
results.ipv4 = [];
|
||||
results.ipv6 = [];
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`[Prometheus] Error fetching target info for ${node}:`, e.message);
|
||||
results.ipv4 = [];
|
||||
results.ipv6 = [];
|
||||
}
|
||||
|
||||
// Group partitions
|
||||
const partitionsMap = {};
|
||||
(results.partitions_size || []).forEach(p => {
|
||||
|
||||
Reference in New Issue
Block a user