vboxInfo() added stoppedSince, started, stopped

This commit is contained in:
Sebastian Hildebrandt 2019-06-01 10:23:14 +02:00
parent 52b48496fb
commit 656c222b0a
7 changed files with 59 additions and 6 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 4.8.3 | 2019-06-01 | `vboxInfo()` added stoppedSince, started, stopped |
| 4.8.2 | 2019-05-31 | `dockerInfo()` changed property naming style |
| 4.8.1 | 2019-05-31 | updated docs |
| 4.8.0 | 2019-05-31 | added `vboxInfo()` detailed virtual box info |

View File

@ -555,7 +555,10 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| | [0].id | X | X | X | X | X | virtual box ID |
| | [0].name | X | X | X | X | X | name |
| | [0].running | X | X | X | X | X | vbox is running |
| | [0].started | X | X | X | X | X | started date time |
| | [0].runningSince | X | X | X | X | X | running since (secs) |
| | [0].stopped | X | X | X | X | X | stopped date time |
| | [0].stoppedSince | X | X | X | X | X | stopped since (secs) |
| | [0].guestOS | X | X | X | X | X | Guest OK |
| | [0].hardwareUUID | X | X | X | X | X | Hardware UUID |
| | [0].memory | X | X | X | X | X | Memory in MB |

View File

@ -80,6 +80,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.8.3</th>
<td>2019-05-31</td>
<td><span class="code">vboxInfo()</span> added stoppedSince, started, stopped</td>
</tr>
<tr>
<th scope="row">4.8.2</th>
<td>2019-05-31</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.8.2</span></div>
<div class="version">Current Version: <span id="version">4.8.3</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

View File

@ -105,6 +105,16 @@
<td>X</td>
<td>vbox is running</td>
</tr>
<tr>
<td></td>
<td>[0].started</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>started date time</td>
</tr>
<tr>
<td></td>
<td>[0].runningSince</td>
@ -115,6 +125,26 @@
<td>X</td>
<td>running since (secs)</td>
</tr>
<tr>
<td></td>
<td>[0].stopped</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>stopped date time</td>
</tr>
<tr>
<td></td>
<td>[0].stoppedSince</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>stopped since (secs)</td>
</tr>
<tr>
<td></td>
<td>[0].guestOS</td>

3
lib/index.d.ts vendored
View File

@ -526,7 +526,10 @@ export namespace Systeminformation {
id: string;
name: string;
running: boolean;
started: string;
runningSince: number;
stopped: string;
stoppedSince: number;
guestOS: string;
hardwareUUID: string;
memory: number;

View File

@ -31,13 +31,10 @@ function vboxInfo(all, callback) {
process.nextTick(() => {
try {
exec(util.getVboxmanage() + ' list vms --long', function (error, stdout) {
let parts = stdout.toString().split('Name:');
let parts = (os.EOL + stdout.toString()).split(os.EOL + 'Name:');
parts.shift();
parts.forEach(part => {
const lines = part.split(os.EOL);
if (lines && lines[0]) {
lines[0] = 'Name:' + lines[0];
}
const lines = ('Name:' + part).split(os.EOL);
const state = util.getValue(lines, 'State');
const running = state.startsWith('running');
const runningSinceString = running ? state.replace('running (since ', '').replace(')', '').trim() : '';
@ -51,11 +48,25 @@ function vboxInfo(all, callback) {
} catch (e) {
util.noop();
}
const stoppedSinceString = !running ? state.replace('powered off (since', '').replace(')', '').trim() : '';
let stoppedSince = 0;
try {
if (!running) {
const sinceDateObj = new Date(stoppedSinceString);
const offset = sinceDateObj.getTimezoneOffset();
stoppedSince = Math.round((Date.now() - Date.parse(sinceDateObj)) / 1000) + offset * 60;
}
} catch (e) {
util.noop();
}
result.push({
id: util.getValue(lines, 'UUID'),
name: util.getValue(lines, 'Name'),
running,
started: runningSinceString,
runningSince,
stopped: stoppedSinceString,
stoppedSince,
guestOS: util.getValue(lines, 'Guest OS'),
hardwareUUID: util.getValue(lines, 'Hardware UUID'),
memory: parseInt(util.getValue(lines, 'Memory size', ' '), 10),