From 305d264376aef987a93e7a54058db0197267d426 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 25 Feb 2021 08:04:31 +0100 Subject: [PATCH] dockerVolumes() added --- CHANGELOG.md | 5 +++ README.md | 13 +++++-- docs/docker.html | 81 +++++++++++++++++++++++++++++++++++++++++ docs/tests.html | 29 +++++++-------- lib/docker.js | 42 ++++++++++++++++++++++ lib/dockerSocket.js | 87 +++++++++++++++++++-------------------------- lib/index.d.ts | 15 ++++++-- lib/index.js | 1 + test/si.js | 1 + test/test.js | 31 ++++++++-------- 10 files changed, 219 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2ca0f1..4029a73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 | diff --git a/README.md b/README.md index 633ab4b..de680d3 100644 --- a/README.md +++ b/README.md @@ -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
and processes in one single array | #### 17. Virtual Box diff --git a/docs/docker.html b/docs/docker.html index cd1a616..fb7f11c 100644 --- a/docs/docker.html +++ b/docs/docker.html @@ -1216,6 +1216,87 @@ X command and arguments + + si.dockerVolumes(cb) + [{...}] + X + X + X + X + X + returns array of 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) {...} diff --git a/docs/tests.html b/docs/tests.html index 117f10d..7851ad7 100644 --- a/docs/tests.html +++ b/docs/tests.html @@ -62,20 +62,21 @@
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            │
-└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
+┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ 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 │ +└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Press q to exit the test suite

Here a sample output for the e.g. c ... CPU

┌────────────────────────────────────────────────┐
diff --git a/lib/docker.js b/lib/docker.js
index e4d3678..845f0cd 100644
--- a/lib/docker.js
+++ b/lib/docker.js
@@ -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(() => {
diff --git a/lib/dockerSocket.js b/lib/dockerSocket.js
index a9d5ea6..0b989b7 100644
--- a/lib/dockerSocket.js
+++ b/lib/dockerSocket.js
@@ -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;
diff --git a/lib/index.d.ts b/lib/index.d.ts
index 889d33b..cf3fe46 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -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;
 
 export function dockerInfo(cb?: (data: Systeminformation.DockerInfoData) => any): Promise;
-export function dockerImages(all?: boolean, cb?: (data: dockerstats.DockerImageData[]) => any): Promise;
+export function dockerImages(all?: boolean, cb?: (data: Systeminformation.DockerImageData[]) => any): Promise;
 export function dockerContainers(all?: boolean, cb?: (data: Systeminformation.DockerContainerData[]) => any): Promise;
 export function dockerContainerStats(id?: string, cb?: (data: Systeminformation.DockerContainerStatsData[]) => any): Promise;
 export function dockerContainerProcesses(id?: string, cb?: (data: any) => any): Promise;
+export function dockerVolumes(cb?: (data: Systeminformation.DockerVolumeData[]) => any): Promise;
 export function dockerAll(cb?: (data: any) => any): Promise;
 
 export function vboxInfo(cb?: (data: Systeminformation.VboxInfoData[]) => any): Promise;
diff --git a/lib/index.js b/lib/index.js
index cd365ac..4e804a4 100755
--- a/lib/index.js
+++ b/lib/index.js
@@ -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;
diff --git a/test/si.js b/test/si.js
index 513d122..55cb8c5 100644
--- a/test/si.js
+++ b/test/si.js
@@ -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'); } }); }
diff --git a/test/test.js b/test/test.js
index ce8ea65..4ed9660 100644
--- a/test/test.js
+++ b/test/test.js
@@ -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() {