dockerVolumes() added

This commit is contained in:
Sebastian Hildebrandt 2021-02-25 08:04:31 +01:00
parent ef6d0a76c4
commit 305d264376
10 changed files with 219 additions and 86 deletions

View File

@ -6,6 +6,8 @@
- `audio()` detailed audio information
- `bluetoothDevices()` detailed information detected bluetooth devices
- `dockerImages()` detailed information docker images
- `dockerVolumes()` detailed information docker volumes
- `printers()` detailed printer information
- `usb()` detailed USB information
- `wifiInterfaces()` detected Wi-Fi interfaces
@ -44,6 +46,7 @@ We had to make **several interface changes** to keep systeminformation as consis
- `cpu()`: extended socket list (win)
- `cpu()`: added virtualization if cpu supports virtualization
- `cpu()`: now flags are part of this function
- `diskLayout()`: added USB drives (mac OS)
- `fsSize()`: added available
- `fsSize()`: improved calculation of used
- `getData()`: support for passing parameters and filters (see section General / getData)
@ -53,6 +56,7 @@ We had to make **several interface changes** to keep systeminformation as consis
- `memoryLayout()`: added ECC flag
- `osInfo()`: better fqdn (win)
- `osinfo()`: added hypervizor if hyper-v is enabled (win only)
- `osInfo()`: added remoteSession (win only)
- `system()`: better Raspberry PI detection
- `system()`: added virtual and virtualHost (if system is virtual instance)
- `uuid()`: better value support
@ -72,6 +76,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 5.5.0 | 2021-02-25 | `dockerVolumes()` added |
| 5.4.0 | 2021-02-24 | `dockerImages()` added |
| 5.3.5 | 2021-02-23 | `dockerContainerStats()` fixed parameter * |
| 5.3.4 | 2021-02-20 | `sanitizeShellString()` optimized strict sanitation |

View File

@ -40,7 +40,7 @@ This next major version release 5.0 comes with new functionality and several imp
- added audio: get detailed audio device information
- added bluetooth: get detailed bluetooth device information
- added dockerImages: get detailed information about docker images
- added dockerImages, dockerVolumes: get detailed information about docker images and volumes
- added printer: get information from detected printers
- added usb: get detailed usb controller and device information
- added wifi interfaces ans connections: extended wifi information
@ -103,6 +103,7 @@ si.cpu()
(last 7 major and minor version releases)
- Version 5.5.0: `dockerVolumes()` added
- Version 5.4.0: `dockerImages()` added
- Version 5.3.0: `osInfo()` added remoteSession (win only)
- Version 5.2.0: `wifiInterfaces()` and `wifiConnections()` added
@ -110,8 +111,6 @@ si.cpu()
- Version 5.0.0: new version 5 - attention there are some breaking changes. See [detailed version 5 changes here][changes5-url].
- Version 4.34.0: `system()` added flag virtual (linux, windows)
- Version 4.33.0: `graphics()` added nvidia-smi support (linux, windows)
- Version 4.32.0: `graphics()` added clinfo support (linux)
- Version 4.31.0: `osInfo()` added FQDN
- ...
You can find all changes here: [detailed changelog][changelog-url]
@ -734,6 +733,14 @@ Full function reference with examples can be found at [https://systeminformation
| | [0].rss | X | X | X | X | X | resident set size |
| | [0].vsz | X | X | X | X | X | virtual size in Kbytes |
| | [0].command | X | X | X | X | X | command and arguments |
| si.dockerVolumes(cb) | [{...}] | returns array of all docker volumes |
| | [0].name | X | X | X | X | X | volume name |
| | [0].driver | X | X | X | X | X | driver |
| | [0].labels | X | X | X | X | X | labels object |
| | [0].mountpoint | X | X | X | X | X | mountpoint |
| | [0].options | X | X | X | X | X | options |
| | [0].scope | X | X | X | X | X | scope |
| | [0].created | X | X | X | X | X | created at |
| si.dockerAll(cb) | {...} | X | X | X | X | X | list of all containers including their stats<br>and processes in one single array |
#### 17. Virtual Box

View File

@ -1216,6 +1216,87 @@
<td>X</td>
<td>command and arguments</td>
</tr>
<tr>
<td>si.dockerVolumes(cb)</td>
<td>[{...}]</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>returns array of docker volumes</td>
</tr>
<tr>
<td></td>
<td>[0].name</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>volume name</td>
</tr>
<tr>
<td></td>
<td>[0].driver</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>driver</td>
</tr>
<tr>
<td></td>
<td>[0].labels</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>labels object</td>
</tr>
<tr>
<td></td>
<td>[0].mountpoint</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>mountpoint</td>
</tr>
<tr>
<td></td>
<td>[0].options</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>options</td>
</tr>
<tr>
<td></td>
<td>[0].scope</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>scope</td>
</tr>
<tr>
<td></td>
<td>[0].created</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>created at</td>
</tr>
<tr>
<td>si.dockerAll(cb)</td>
<td>{...}</td>

View File

@ -62,20 +62,21 @@
<pre><code class="js">SYSTEMINFORMATION - Test Scripts - Version: 5.x.y
═══════════════════════════════════════════════════════════
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ a ... Audio h ... Bluetooth s ... Services Y ... Battery ? ... Get Object │
│ b ... BIOS i ... INET Latency S ... Shell z ... Users , ... All Static │
│ B ... Baseboard I ... INET Check Site t ... time 1 ... NET Iface Default . ... All Dynamic │
│ C ... Chassis j ... CPU Current Speed T ... CPU Temperature 2 ... NET Gateway Default / ... All │
│ c ... CPU l ... CPU Current Load u ... USB 3 ... NET Interfaces │
│ d ... DiskLayout L ... Full Load U ... UUID 4 ... NET Stats │
│ D ... DiskIO m ... Memory v ... Versions 5 ... NET Connections │
│ e ... Block Devices M ... MEM Layout V ... Virtual Box 6 ... Docker Info │
│ E ... Open Files o ... OS Info w ... WIFI networks 7 ... Docker Container │
│ f ... FS Size p ... Processes W ... WIFI interfaces 8 ... Docker Cont Stats │
│ F ... FS Stats P ... Process Load x ... WIFI connections 9 ... Docker Cont Proc │
│ g ... Graphics r ... Printer y ... System 0 ... Docker All q >>> QUIT │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘</code></pre>
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ a ... Audio i ... INET Latency t ... time 1 ... NET Iface Default ? ... Get Object │
│ b ... BIOS I ... INET Check Site T ... CPU Temperature 2 ... NET Gateway Default , ... All Static │
│ B ... Baseboard j ... CPU Current Speed u ... USB 3 ... NET Interfaces . ... All Dynamic │
│ C ... Chassis l ... CPU Current Load U ... UUID 4 ... NET Stats / ... All │
│ c ... CPU L ... Full Load v ... Versions 5 ... NET Connections │
│ d ... DiskLayout m ... Memory V ... Virtual Box │
│ D ... DiskIO M ... MEM Layout w ... WIFI networks │
│ e ... Block Devices o ... OS Info W ... WIFI interfaces │
│ E ... Open Files p ... Processes x ... WIFI connections 6 ... Docker Info │
│ f ... FS Size P ... Process Load y ... System 7 ... Docker Images │
│ F ... FS Stats r ... Printer Y ... Battery 8 ... Docker Container │
│ g ... Graphics s ... Services z ... Users 9 ... Docker Cont Stats │
│ h ... Bluetooth S ... Shell 0 ... Docker Cont Proc q >>> QUIT │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘</code></pre>
<p><span class="bold">Press q</span> to exit the test suite</p>
<p>Here a sample output for the e.g. <span class="bold">c ... CPU</span></p>
<pre><code class="js">┌────────────────────────────────────────────────┐

View File

@ -666,6 +666,48 @@ function dockerContainerProcesses(containerID, callback) {
exports.dockerContainerProcesses = dockerContainerProcesses;
function dockerVolumes(callback) {
let result = [];
return new Promise((resolve) => {
process.nextTick(() => {
if (!_docker_socket) {
_docker_socket = new DockerSocket();
}
_docker_socket.listVolumes(data => {
let dockerVolumes = {};
try {
dockerVolumes = data;
if (dockerVolumes && dockerVolumes.Volumes && Object.prototype.toString.call(dockerVolumes.Volumes) === '[object Array]' && dockerVolumes.Volumes.length > 0) {
dockerVolumes.Volumes.forEach(function (element) {
result.push({
name: element.Name,
driver: element.Driver,
labels: element.Labels,
mountpoint: element.Mountpoint,
options: element.Options,
scope: element.Scope,
created: element.CreatedAt ? Math.round(new Date(element.CreatedAt).getTime() / 1000) : 0,
});
});
if (callback) { callback(result); }
resolve(result);
} else {
if (callback) { callback(result); }
resolve(result);
}
} catch (err) {
if (callback) { callback(result); }
resolve(result);
}
});
});
});
}
exports.dockerVolumes = dockerVolumes;
function dockerAll(callback) {
return new Promise((resolve) => {
process.nextTick(() => {

View File

@ -167,57 +167,6 @@ class DockerSocket {
}
}
listVolumes(filter, callback) {
try {
let socket = net.createConnection({ path: socketPath });
let alldata = '';
let data;
filter = filter || {};
let filterString = '';
if (filter.dangling && typeof filter.dangling === 'boolean') {
filterString += (filterString ? '&' : '') + 'dangling=true';
}
if (filter.driver && typeof filter.driver === 'string') {
filterString += (filterString ? '&' : '') + `driver=${filter.driver}`;
}
if (filter.label && typeof filter.label === 'string') {
filterString += (filterString ? '&' : '') + `label=${filter.label}`;
}
if (filter.name && typeof filter.name === 'string') {
filterString += (filterString ? '&' : '') + `name=${filter.name}`;
}
socket.on('connect', () => {
socket.write('GET http:/volumes/' + (filterString ? `?${filterString}` : '') + ' HTTP/1.0\r\n\r\n');
});
socket.on('data', data => {
alldata = alldata + data.toString();
});
socket.on('error', () => {
socket = false;
callback({});
});
socket.on('end', () => {
let startbody = alldata.indexOf('\r\n\r\n');
alldata = alldata.substring(startbody + 4);
socket = false;
try {
data = JSON.parse(alldata);
callback(data);
} catch (err) {
callback({});
}
});
} catch (err) {
callback({});
}
}
getStats(id, callback) {
id = id || '';
if (id) {
@ -337,6 +286,42 @@ class DockerSocket {
callback({});
}
}
listVolumes(callback) {
try {
let socket = net.createConnection({ path: socketPath });
let alldata = '';
let data;
socket.on('connect', () => {
socket.write('GET http:/volumes HTTP/1.0\r\n\r\n');
});
socket.on('data', data => {
alldata = alldata + data.toString();
});
socket.on('error', () => {
socket = false;
callback({});
});
socket.on('end', () => {
let startbody = alldata.indexOf('\r\n\r\n');
alldata = alldata.substring(startbody + 4);
socket = false;
try {
data = JSON.parse(alldata);
callback(data);
} catch (err) {
callback({});
}
});
} catch (err) {
callback({});
}
}
}
module.exports = DockerSocket;

15
lib/index.d.ts vendored
View File

@ -660,7 +660,7 @@ export namespace Systeminformation {
repoTags: any;
config: any;
rootFS: any;
}
}
interface DockerContainerData {
id: string;
@ -712,6 +712,16 @@ export namespace Systeminformation {
networks: any;
}
interface DockerVolumeData {
name: string;
driver: string;
labels: any;
mountpoint: string;
options: any;
scope: string;
created: number;
}
// 9. Virtual Box
interface VboxInfoData {
@ -872,10 +882,11 @@ export function processLoad(processName: string, cb?: (data: Systeminformation.P
export function services(serviceName: string, cb?: (data: Systeminformation.ServicesData[]) => any): Promise<Systeminformation.ServicesData[]>;
export function dockerInfo(cb?: (data: Systeminformation.DockerInfoData) => any): Promise<Systeminformation.DockerInfoData>;
export function dockerImages(all?: boolean, cb?: (data: dockerstats.DockerImageData[]) => any): Promise<dockerstats.DockerImageData[]>;
export function dockerImages(all?: boolean, cb?: (data: Systeminformation.DockerImageData[]) => any): Promise<Systeminformation.DockerImageData[]>;
export function dockerContainers(all?: boolean, cb?: (data: Systeminformation.DockerContainerData[]) => any): Promise<Systeminformation.DockerContainerData[]>;
export function dockerContainerStats(id?: string, cb?: (data: Systeminformation.DockerContainerStatsData[]) => any): Promise<Systeminformation.DockerContainerStatsData[]>;
export function dockerContainerProcesses(id?: string, cb?: (data: any) => any): Promise<any>;
export function dockerVolumes(cb?: (data: Systeminformation.DockerVolumeData[]) => any): Promise<Systeminformation.DockerVolumeData[]>;
export function dockerAll(cb?: (data: any) => any): Promise<any>;
export function vboxInfo(cb?: (data: Systeminformation.VboxInfoData[]) => any): Promise<Systeminformation.VboxInfoData[]>;

View File

@ -486,6 +486,7 @@ exports.dockerImages = docker.dockerImages;
exports.dockerContainers = docker.dockerContainers;
exports.dockerContainerStats = docker.dockerContainerStats;
exports.dockerContainerProcesses = docker.dockerContainerProcesses;
exports.dockerVolumes = docker.dockerVolumes;
exports.dockerAll = docker.dockerAll;
exports.vboxInfo = vbox.vboxInfo;

View File

@ -53,6 +53,7 @@ function test(f) {
else if (f === '8') { si.dockerContainers(true).then(data => { if (data !== null) { resolve({ data, title: 'Docker Containers' }); } else { resolve('not_supported'); } }); }
else if (f === '9') { si.dockerContainerStats('*').then(data => { if (data !== null) { resolve({ data, title: 'Docker Cont Stats' }); } else { resolve('not_supported'); } }); }
else if (f === '0') { si.dockerContainerProcesses('*').then(data => { if (data !== null) { resolve({ data, title: 'Docker Cont Processes' }); } else { resolve('not_supported'); } }); }
else if (f === '+') { si.dockerVolumes().then(data => { if (data !== null) { resolve({ data, title: 'Docker Volumes' }); } else { resolve('not_supported'); } }); }
else if (f === ',') { si.getStaticData().then(data => { if (data !== null) { resolve({ data, title: 'All Static Data' }); } else { resolve('not_supported'); } }); }
else if (f === '.') { si.getDynamicData('apache2, postgres, wsearch').then(data => { if (data !== null) { resolve({ data, title: 'All Dynamic Data' }); } else { resolve('not_supported'); } }); }
else if (f === '/') { si.getAllData('apache2, postgres, wsearch').then(data => { if (data !== null) { resolve({ data, title: 'All Data' }); } else { resolve('not_supported'); } }); }

View File

@ -15,22 +15,21 @@ function printHeader() {
function printMenu() {
console.log('');
console.log('┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐');
console.log('│ a ... Audio i ... INET Latency t ... time 1 ... NET Iface Default ? ... Get Object │');
console.log('│ b ... BIOS I ... INET Check Site T ... CPU Temperature 2 ... NET Gateway Default , ... All Static │');
console.log('│ B ... Baseboard j ... CPU Current Speed u ... USB 3 ... NET Interfaces . ... All Dynamic │');
console.log('│ C ... Chassis l ... CPU Current Load U ... UUID 4 ... NET Stats / ... All │');
console.log('│ c ... CPU L ... Full Load v ... Versions 5 ... NET Connections │');
console.log('│ d ... DiskLayout m ... Memory V ... Virtual Box │');
console.log('│ D ... DiskIO M ... MEM Layout w ... WIFI networks │');
console.log('│ e ... Block Devices o ... OS Info W ... WIFI interfaces │');
console.log('│ E ... Open Files p ... Processes x ... WIFI connections 6 ... Docker Info │');
console.log('│ f ... FS Size P ... Process Load y ... System 7 ... Docker Images │');
console.log('│ F ... FS Stats r ... Printer Y ... Battery 8 ... Docker Container │');
console.log('│ g ... Graphics s ... Services z ... Users 9 ... Docker Cont Stats │');
console.log('│ h ... Bluetooth S ... Shell 0 ... Docker Cont Proc q >>> QUIT │');
console.log('└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘');
console.log('┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐');
console.log('│ a ... Audio i ... INET Latency t ... time 1 ... NET Iface Default ? ... Get Object │');
console.log('│ b ... BIOS I ... INET Check Site T ... CPU Temperature 2 ... NET Gateway Default , ... All Static │');
console.log('│ B ... Baseboard j ... CPU Current Speed u ... USB 3 ... NET Interfaces . ... All Dynamic │');
console.log('│ C ... Chassis l ... CPU Current Load U ... UUID 4 ... NET Stats / ... All │');
console.log('│ c ... CPU L ... Full Load v ... Versions 5 ... NET Connections │');
console.log('│ d ... DiskLayout m ... Memory V ... Virtual Box │');
console.log('│ D ... DiskIO M ... MEM Layout w ... WIFI networks │');
console.log('│ e ... Block Devices o ... OS Info W ... WIFI interfaces 6 ... Docker Info │');
console.log('│ E ... Open Files p ... Processes x ... WIFI connections 7 ... Docker Images │');
console.log('│ f ... FS Size P ... Process Load y ... System 8 ... Docker Container │');
console.log('│ F ... FS Stats r ... Printer Y ... Battery 9 ... Docker Cont Stats │');
console.log('│ g ... Graphics s ... Services z ... Users 0 ... Docker Cont Proc │');
console.log('│ h ... Bluetooth S ... Shell + ... Docker Volumes q >>> QUIT │');
console.log('└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘');
}
function EnableUserInput() {