Skip to content

Commit

Permalink
dockerVolumes() added
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Feb 25, 2021
1 parent ef6d0a7 commit 305d264
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 86 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 |
Expand Down
13 changes: 10 additions & 3 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -103,15 +103,14 @@ 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
- Version 5.1.0: `memLayout()` added ECC flag, `bios()` added language, features (linux)
- 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]
Expand Down Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions docs/docker.html
Expand Up @@ -1216,6 +1216,87 @@ <h2>Container, Stats, Processes</h2>
<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>
Expand Down
29 changes: 15 additions & 14 deletions docs/tests.html
Expand Up @@ -62,20 +62,21 @@ <h2>Testing on your platform</h2>
<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">┌────────────────────────────────────────────────┐
Expand Down
42 changes: 42 additions & 0 deletions lib/docker.js
Expand Up @@ -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(() => {
Expand Down
87 changes: 36 additions & 51 deletions lib/dockerSocket.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 changes: 13 additions & 2 deletions lib/index.d.ts
Expand Up @@ -660,7 +660,7 @@ export namespace Systeminformation {
repoTags: any;
config: any;
rootFS: any;
}
}

interface DockerContainerData {
id: string;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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[]>;
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -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;
Expand Down

0 comments on commit 305d264

Please sign in to comment.