update
This commit is contained in:
+11
-2
@@ -334,6 +334,14 @@
|
|||||||
return new Date(timestamp * 1000).toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
return new Date(timestamp * 1000).toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NEW: Format disk space intelligently (TB if ≥ 1024 GB, otherwise GB)
|
||||||
|
function formatDiskSpace(gbValue) {
|
||||||
|
if (gbValue >= 1024) {
|
||||||
|
return `${(gbValue / 1024).toFixed(2)} TB`;
|
||||||
|
}
|
||||||
|
return `${gbValue.toFixed(2)} GB`;
|
||||||
|
}
|
||||||
|
|
||||||
function initCharts() {
|
function initCharts() {
|
||||||
if (typeof Chart === 'undefined') {
|
if (typeof Chart === 'undefined') {
|
||||||
console.error('Chart.js failed to load.');
|
console.error('Chart.js failed to load.');
|
||||||
@@ -669,8 +677,9 @@
|
|||||||
const diskSpaceData = data.netdata.disk_space || [];
|
const diskSpaceData = data.netdata.disk_space || [];
|
||||||
const latestDiskSpace = diskSpaceData.length > 0 ? diskSpaceData[diskSpaceData.length - 1] : null;
|
const latestDiskSpace = diskSpaceData.length > 0 ? diskSpaceData[diskSpaceData.length - 1] : null;
|
||||||
document.getElementById('disk-usage').textContent = latestDiskSpace ? `${latestDiskSpace.used.toFixed(2)} GB` : '0 GB';
|
document.getElementById('disk-usage').textContent = latestDiskSpace ? `${latestDiskSpace.used.toFixed(2)} GB` : '0 GB';
|
||||||
document.getElementById('free-disk').textContent = latestDiskSpace ? `${latestDiskSpace.avail.toFixed(2)} GB` : '0 GB';
|
document.getElementById('free-disk').textContent = latestDiskSpace
|
||||||
|
? formatDiskSpace(latestDiskSpace.avail)
|
||||||
|
: '0 GB';
|
||||||
const anomalyData = data.netdata.anomaly || [];
|
const anomalyData = data.netdata.anomaly || [];
|
||||||
const latestAnomaly = anomalyData.length > 0 ? anomalyData[anomalyData.length - 1] : null;
|
const latestAnomaly = anomalyData.length > 0 ? anomalyData[anomalyData.length - 1] : null;
|
||||||
document.getElementById('ai-fault-count').textContent = latestAnomaly ? `${latestAnomaly.anomalous}` : '0';
|
document.getElementById('ai-fault-count').textContent = latestAnomaly ? `${latestAnomaly.anomalous}` : '0';
|
||||||
|
|||||||
+4
-4
@@ -163,6 +163,7 @@ async function getDockerStats() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch Netdata metrics
|
||||||
// Fetch Netdata metrics
|
// Fetch Netdata metrics
|
||||||
async function getNetdataMetrics() {
|
async function getNetdataMetrics() {
|
||||||
if (!NETDATA_URL) {
|
if (!NETDATA_URL) {
|
||||||
@@ -176,8 +177,8 @@ async function getNetdataMetrics() {
|
|||||||
{ key: 'ram', url: `${NETDATA_URL}/api/v3/data?contexts=system.ram&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], used: d[2], free: d[1] }) },
|
{ key: 'ram', url: `${NETDATA_URL}/api/v3/data?contexts=system.ram&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], used: d[2], free: d[1] }) },
|
||||||
{ key: 'net', url: `${NETDATA_URL}/api/v3/data?contexts=system.net&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], received: d[1], sent: d[2] }) },
|
{ key: 'net', url: `${NETDATA_URL}/api/v3/data?contexts=system.net&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], received: d[1], sent: d[2] }) },
|
||||||
{ key: 'disk', url: `${NETDATA_URL}/api/v3/data?contexts=system.io&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
|
{ key: 'disk', url: `${NETDATA_URL}/api/v3/data?contexts=system.io&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
|
||||||
{ key: 'disk_space', url: `${NETDATA_URL}/api/v3/data?contexts=disk.space&labels=mount_point:%2F&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) },
|
// Fixed: Targets the large /docker-data volume (2TB disk)
|
||||||
{ key: 'anomaly', url: `${NETDATA_URL}/api/v3/data?contexts=anomaly_detection.dimensions&scope_nodes=mchost&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) },
|
{ key: 'disk_space', url: `${NETDATA_URL}/api/v3/data?contexts=disk.space&labels=mount_point:%2Fdocker-data&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) }, { key: 'anomaly', url: `${NETDATA_URL}/api/v3/data?contexts=anomaly_detection.dimensions&scope_nodes=mchost&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) },
|
||||||
{ key: 'load', url: `${NETDATA_URL}/api/v3/data?contexts=system.load&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], load1: d[1], load5: d[2], load15: d[3] }) }
|
{ key: 'load', url: `${NETDATA_URL}/api/v3/data?contexts=system.load&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], load1: d[1], load5: d[2], load15: d[3] }) }
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -209,8 +210,7 @@ async function getNetdataMetrics() {
|
|||||||
return { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [], load: [] };
|
return { cpu: [], ram: [], net: [], disk: [], disk_space: [], anomaly: [], load: [] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Fetch Jump Node metrics (unchanged)
|
||||||
// Fetch Jump Node metrics
|
|
||||||
async function getJumpNodeMetrics() {
|
async function getJumpNodeMetrics() {
|
||||||
if (!NETDATA_JUMP_URL) {
|
if (!NETDATA_JUMP_URL) {
|
||||||
console.error('Cannot fetch Jump Node metrics: NETDATA_JUMP_URL is undefined.');
|
console.error('Cannot fetch Jump Node metrics: NETDATA_JUMP_URL is undefined.');
|
||||||
|
|||||||
Reference in New Issue
Block a user