Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export default function EditorMenu({ children }) {
{children.map(
(child) =>
child && (
<li className="editor-menu-item" key={crypto.randomUUID()}>
<li className="editor-menu-item" key={crypto.randomUUID?.() ?? Math.random().toString().slice(2)}>
{child}
</li>
),
)
)}
</ul>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function FileMenu({ children }) {
{children.map(
(child) =>
child && (
<li className="file-menu-item" key={crypto.randomUUID()}>
<li className="file-menu-item" key={crypto.randomUUID?.() ?? Math.random().toString().slice(2)}>
{child}
</li>
),
)
)}
</ul>
);
Expand Down
4 changes: 2 additions & 2 deletions src/functions/api/instance/getComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function addMetadata(fileTree, path, rootDir, readOnly = false) {

if (path === rootDir) {
fileTree.path = rootDir;
fileTree.key = crypto.randomUUID();
fileTree.key = crypto.randomUUID?.() ?? Math.random().toString().slice(2);
}

for (const entry of fileTree.entries) {
Expand All @@ -24,7 +24,7 @@ function addMetadata(fileTree, path, rootDir, readOnly = false) {
const [, project] = newPath.split('/');
entry.project = project;
entry.path = newPath;
entry.key = crypto.randomUUID();
entry.key = crypto.randomUUID?.() ?? Math.random().toString().slice(2);
entry.readOnly = readOnly || !!entry.package;

addMetadata(entry, newPath, rootDir, entry.readOnly);
Expand Down
116 changes: 46 additions & 70 deletions src/functions/api/instance/updateSystemInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import instanceState from '../../state/instanceState';
const B2GB1000 = 1000000000; // for mac disk and transfer
const B2GB1024 = 1073741824; // for non-mac disk

export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo, skip=[] }) => {

export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo, skip = [] }) => {
// skip attributes added because network and disk currently expensive instance ops
// provides more fine-grained control over which items are cached.

const systemAttributes = ['network','disk','cpu','memory','system'];
const systemAttributes = ['network', 'disk', 'cpu', 'memory', 'system'];
const result = await queryInstance({
operation: {
operation: 'system_information',
attributes: skip?.length ?
systemAttributes.filter(attr => !skip.includes(attr)) :
systemAttributes,
attributes: skip?.length ? systemAttributes.filter((attr) => !skip.includes(attr)) : systemAttributes,
},
auth,
url,
Expand Down Expand Up @@ -52,76 +49,56 @@ export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo,
});
}


// MEMORY
const totalMemory = skip.includes('memory') ?
parseFloat(cachedSystemInfo.totalMemory) :
result.memory.total / B2GB1024;
const usedMemory = skip.includes('memory') ?
parseFloat(cachedSystemInfo.usedMemory) :
result.memory.active / B2GB1024;
const freeMemory = skip.includes('memory') ?
parseFloat(cachedSystemInfo.freeMemory) :
result.memory.available / B2GB1024;
const memoryStatus = skip.includes('memory') ?
cachedSystemInfo.memoryStatus :
freeMemory / totalMemory < 0.1 ?
'danger' :
freeMemory / totalMemory < 0.25 ? 'warning' : 'success';
const totalMemory = skip.includes('memory') ? parseFloat(cachedSystemInfo.totalMemory) : result.memory.total / B2GB1024;
const usedMemory = skip.includes('memory') ? parseFloat(cachedSystemInfo.usedMemory) : result.memory.active / B2GB1024;
const freeMemory = skip.includes('memory') ? parseFloat(cachedSystemInfo.freeMemory) : result.memory.available / B2GB1024;
const memoryStatus = skip.includes('memory')
? cachedSystemInfo.memoryStatus
: freeMemory / totalMemory < 0.1
? 'danger'
: freeMemory / totalMemory < 0.25
? 'warning'
: 'success';

// DISK
const totalDisk = skip.includes('disk') ?
parseFloat(cachedSystemInfo.totalDisk) :
result.system.platform === 'darwin' ?
result.disk.size[0].size / B2GB1000 :
!is_local ?
result.disk.size.find((disk) => disk.mount === '/home/ubuntu/hdb').size / B2GB1024 :
result.disk.size[0].size / B2GB1024;

const usedDisk = skip.includes('disk') ?
parseFloat(cachedSystemInfo.usedDisk) :
result.system.platform === 'darwin' ?
result.disk.size.reduce((a, b) => a + b.used, 0) / B2GB1000 :
!is_local ?
result.disk.size.find((disk) => disk.mount === '/home/ubuntu/hdb').used / B2GB1024 :
result.disk.size.reduce((a, b) => a + b.used, 0) / B2GB1024;

const freeDisk = skip.includes('disk') ?
parseFloat(cachedSystemInfo.freeDisk) :
totalDisk - usedDisk;

const diskStatus = skip.includes('disk') ?
cachedSystemInfo.diskStatus :
freeDisk / totalDisk < 0.1 ?
'danger' : freeDisk / totalDisk < 0.25 ?
'warning' : 'success';
const totalDisk = skip.includes('disk')
? parseFloat(cachedSystemInfo.totalDisk)
: result.system.platform === 'darwin'
? result.disk.size?.[0].size / B2GB1000
: !is_local
? result.disk.size?.find((disk) => disk.mount === '/home/ubuntu/hdb').size / B2GB1024
: result.disk.size?.[0].size / B2GB1024;

const usedDisk = skip.includes('disk')
? parseFloat(cachedSystemInfo.usedDisk)
: result.system.platform === 'darwin'
? result.disk.size?.reduce((a, b) => a + b.used, 0) / B2GB1000
: !is_local
? result.disk.size?.find((disk) => disk.mount === '/home/ubuntu/hdb').used / B2GB1024
: result.disk.size?.reduce((a, b) => a + b.used, 0) / B2GB1024;

const freeDisk = skip.includes('disk') ? parseFloat(cachedSystemInfo.freeDisk) : totalDisk - usedDisk;

const diskStatus = skip.includes('disk') ? cachedSystemInfo.diskStatus : freeDisk / totalDisk < 0.1 ? 'danger' : freeDisk / totalDisk < 0.25 ? 'warning' : 'success';

// CPU
const cpuInfo = skip.includes('cpu') ?
cachedSystemInfo.cpuInfo : `${result.cpu.manufacturer} ${result.cpu.brand}`;
const cpuCores = skip.includes('cpu') ?
cachedSystemInfo.cpuCores : `${result.cpu.physicalCores} physical / ${result.cpu.cores} virtual`;
const cpuLoad = skip.includes('cpu') ?
parseFloat(cachedSystemInfo.cpuLoad) : result.cpu.current_load.currentLoad || result.cpu.current_load.currentload || 0;
const cpuStatus = skip.includes('cpu') ?
cachedSystemInfo.cpuStatus :
cpuLoad > 90 ?
'danger' : cpuLoad > 75 ?
'warning' : 'success';
const cpuInfo = skip.includes('cpu') ? cachedSystemInfo.cpuInfo : `${result.cpu.manufacturer} ${result.cpu.brand}`;
const cpuCores = skip.includes('cpu') ? cachedSystemInfo.cpuCores : `${result.cpu.physicalCores} physical / ${result.cpu.cores} virtual`;
const cpuLoad = skip.includes('cpu') ? parseFloat(cachedSystemInfo.cpuLoad) : result.cpu.current_load.currentLoad || result.cpu.current_load.currentload || 0;
const cpuStatus = skip.includes('cpu') ? cachedSystemInfo.cpuStatus : cpuLoad > 90 ? 'danger' : cpuLoad > 75 ? 'warning' : 'success';

// NETWORK
const networkTransferred = skip.includes('network') ?
parseFloat(cachedSystemInfo.networkTransferred) :
result.network.stats.reduce((a, b) => a + b.tx_bytes, 0) / B2GB1000;
const networkReceived = skip.includes('network') ?
parseFloat(cachedSystemInfo.networkReceived) :
result.network.stats.reduce((a, b) => a + b.rx_bytes, 0) / B2GB1000;
const networkLatency = skip.includes('network') ?
parseFloat(cachedSystemInfo.networkLatency) :
result.network.latency.ms;
const networkLatencyStatus = skip.includes('network') ?
parseFloat(cachedSystemInfo.networkLatencyStatus) :
networkLatency > 1000 ? 'danger' : networkLatency > 500 ? 'warning' : 'success';
const networkTransferred = skip.includes('network') ? parseFloat(cachedSystemInfo.networkTransferred) : result.network.stats.reduce((a, b) => a + b.tx_bytes, 0) / B2GB1000;
const networkReceived = skip.includes('network') ? parseFloat(cachedSystemInfo.networkReceived) : result.network.stats.reduce((a, b) => a + b.rx_bytes, 0) / B2GB1000;
const networkLatency = skip.includes('network') ? parseFloat(cachedSystemInfo.networkLatency) : result.network.latency.ms;
const networkLatencyStatus = skip.includes('network')
? parseFloat(cachedSystemInfo.networkLatencyStatus)
: networkLatency > 1000
? 'danger'
: networkLatency > 500
? 'warning'
: 'success';

const systemInfo = {
totalMemory: totalMemory?.toFixed(2),
Expand All @@ -145,5 +122,4 @@ export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo,
return instanceState.update((s) => {
s.systemInfo = systemInfo;
});

};