add linux storage volumes using df

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458 2024-05-13 23:44:47 +01:00
parent b71b4d04e6
commit e3f68226d2
4 changed files with 3566 additions and 3472 deletions

View File

@ -138,11 +138,19 @@ function linux_identifiers()
child.stdin.write("lshw -class disk | tr '\\n' '`' | awk '" + '{ len=split($0,lines,"*"); printf "["; for(i=2;i<=len;++i) { model=""; caption=""; size=""; clen=split(lines[i],item,"`"); for(j=2;j<clen;++j) { split(item[j],tokens,":"); split(tokens[1],key," "); if(key[1]=="description") { caption=substr(tokens[2],2); } if(key[1]=="product") { model=substr(tokens[2],2); } if(key[1]=="size") { size=substr(tokens[2],2); } } if(model=="") { model=caption; } if(caption!="" || model!="") { printf "%s{\\"Caption\\":\\"%s\\",\\"Model\\":\\"%s\\",\\"Size\\":\\"%s\\"}",(i==2?"":","),caption,model,size; } } printf "]"; }\'\nexit\n');
child.waitExit();
try { identifiers['storage_devices'] = JSON.parse(child.stdout.str.trim()); } catch (xx) { }
child = null;
// Fetch storage volumes using df
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', dataHandler);
child.stdin.write('df --output=size,used,avail,target,fstype | awk \'NR>1 {printf "{\\"size\\":\\"%s\\",\\"used\\":\\"%s\\",\\"available\\":\\"%s\\",\\"mount_point\\":\\"%s\\",\\"type\\":\\"%s\\"},", $1, $2, $3, $4, $5}\' | sed \'$ s/,$//\' | awk \'BEGIN {printf "["} {printf "%s", $0} END {printf "]"}\'\nexit\n');
child.waitExit();
try { ret.volumes = JSON.parse(child.stdout.str.trim()); } catch (xx) { }
child = null;
values.identifiers = identifiers;
values.linux = ret;
trimIdentifiers(values.identifiers);
child = null;
var dmidecode = require('lib-finder').findBinary('dmidecode');
if (dmidecode != null)

File diff suppressed because it is too large Load Diff

View File

@ -6456,6 +6456,35 @@
if (x != '') { sections.push({ name: "Storage Volumes", html: '<table style=width:100%>' + x + '</table>', img: 'storage'}); }
}
// Linux Volumes
if (hardware.linux && hardware.linux.volumes) {
var x = '';
for (var i in hardware.linux.volumes) {
var m = hardware.linux.volumes[i];
if(m.mount_point.startsWith('/var/lib/docker/overlay2')) continue;
x += '<tr><td><div class=style10 style=border-radius:5px;padding:8px>';
x += '<div style=margin-bottom:3px><b>' + m.mount_point + '</b></div>';
if (m.size) {
var sizes = ['KB', 'MB', 'GB', 'TB'];
var j = parseInt(Math.floor(Math.log(Math.abs(m.size)) / Math.log(1024)), 10);
var fsize = (j === 0 ? `${m.size} ${sizes[j]}` : `${(m.size / (1024 ** j)).toFixed(2)} ${sizes[j]}`);
x += addDetailItem("Capacity", EscapeHtml(fsize), s);
}
if (m.available) {
var sizes = ['KB', 'MB', 'GB', 'TB'];
var j = parseInt(Math.floor(Math.log(Math.abs(m.available)) / Math.log(1024)), 10);
var fsize = (j === 0 ? `${m.available} ${sizes[j]}` : `${(m.available / (1024 ** j)).toFixed(2)} ${sizes[j]}`);
x += addDetailItem("Capacity Remaining", EscapeHtml(fsize), s);
}
if (m.type) {
var type = (m.removable == true ? "Removable" : (m.cdrom == true ? "CD-ROM" : ''));
x += addDetailItem("File System", (type != '' ? (type + ' / ') : '') + (m.type == 'Unknown' ? "Unknown" : EscapeHtml(m.type)), s);
}
x += '</div>';
}
if (x != '') { sections.push({ name: "Storage Volumes", html: '<table style=width:100%>' + x + '</table>', img: 'storage'}); }
}
// Render the sections
var x = '';
for (var i in sections) {

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
@ -12268,6 +12268,35 @@
if (x != '') { sections.push({ name: "Storage Volumes", html: '<table style=width:100%>' + x + '</table>', img: 'storage64.png'}); }
}
// Linux Volumes
if (hardware.linux && hardware.linux.volumes) {
var x = '';
for (var i in hardware.linux.volumes) {
var m = hardware.linux.volumes[i];
if(m.mount_point.startsWith('/var/lib/docker/overlay2')) continue;
x += '<tr><td><div class=style10 style=border-radius:5px;padding:8px>';
x += '<div style=margin-bottom:3px><b>' + m.mount_point + '</b></div>';
if (m.size) {
var sizes = ['KB', 'MB', 'GB', 'TB'];
var j = parseInt(Math.floor(Math.log(Math.abs(m.size)) / Math.log(1024)), 10);
var fsize = (j === 0 ? `${m.size} ${sizes[j]}` : `${(m.size / (1024 ** j)).toFixed(2)} ${sizes[j]}`);
x += addDetailItem("Capacity", EscapeHtml(fsize), s);
}
if (m.available) {
var sizes = ['KB', 'MB', 'GB', 'TB'];
var j = parseInt(Math.floor(Math.log(Math.abs(m.available)) / Math.log(1024)), 10);
var fsize = (j === 0 ? `${m.available} ${sizes[j]}` : `${(m.available / (1024 ** j)).toFixed(2)} ${sizes[j]}`);
x += addDetailItem("Capacity Remaining", EscapeHtml(fsize), s);
}
if (m.type) {
var type = (m.removable == true ? "Removable" : (m.cdrom == true ? "CD-ROM" : ''));
x += addDetailItem("File System", (type != '' ? (type + ' / ') : '') + (m.type == 'Unknown' ? "Unknown" : EscapeHtml(m.type)), s);
}
x += '</div>';
}
if (x != '') { sections.push({ name: "Storage Volumes", html: '<table style=width:100%>' + x + '</table>', img: 'storage64.png'}); }
}
// Render the sections
var x = '';
for (var i in sections) {