processes() fix started (linux alpine)

This commit is contained in:
Sebastian Hildebrandt 2022-12-09 05:34:29 +01:00
parent 3bcc64273a
commit 2dad549e23
4 changed files with 25 additions and 5 deletions

View File

@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
| Version | Date | Comment |
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
| 5.16.3 | 2022-12-09 | `processes()` fix started (linux alpine) |
| 5.16.3 | 2022-12-08 | `users()` fix when multiple explorer.exe (windows) |
| 5.16.2 | 2022-12-08 | `dockerContainerStats()` improved calculation cpuPercent |
| 5.16.1 | 2022-12-04 | code cleanup, moved from lgtm to GitHub Code Scan |

View File

@ -57,9 +57,14 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.16.4</th>
<td>2022-12-09</td>
<td><span class="code">processes()</span> fix started (linux alpine)</td>
</tr>
<tr>
<th scope="row">5.16.3</th>
<td>2022-12-04</td>
<td>2022-12-08</td>
<td><span class="code">users()</span> fix when multiple exporer.exe opened (windows)</td>
</tr>
<tr>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png" alt="logo">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.16.3</span></div>
<div class="version">New Version: <span id="version">5.16.4</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

@ -655,7 +655,7 @@ function processes(callback) {
function formatDateTime(time) {
const month = ('0' + (time.getMonth() + 1).toString()).substr(-2);
const year = time.getFullYear().toString();
const day = ('0' + time.getDay().toString()).substr(-2);
const day = ('0' + time.getDate().toString()).substr(-2);
const hours = time.getHours().toString();
const mins = time.getMinutes().toString();
const secs = ('0' + time.getSeconds().toString()).substr(-2);
@ -663,6 +663,21 @@ function processes(callback) {
return (year + '-' + month + '-' + day + ' ' + hours + ':' + mins + ':' + secs);
}
function parseElapsed(etime) {
let started = '';
if (etime.indexOf('d') >= 0) {
const elapsed_parts = etime.split('d');
started = formatDateTime(new Date(Date.now() - (elapsed_parts[0] * 24 + elapsed_parts[1] * 1) * 60 * 60 * 1000));
} else if (etime.indexOf('h') >= 0) {
const elapsed_parts = etime.split('h');
started = formatDateTime(new Date(Date.now() - (elapsed_parts[0] * 60 + elapsed_parts[1] * 1) * 60 * 1000));
} else if (etime.indexOf(':') >= 0) {
const elapsed_parts = etime.split(':');
started = formatDateTime(new Date(Date.now() - (elapsed_parts.length > 1 ? (elapsed_parts[0] * 60 + elapsed_parts[1]) * 1000 : elapsed_parts[0] * 1000)));
}
return started;
}
let result = [];
lines.forEach(function (line) {
if (line.trim() !== '') {
@ -670,8 +685,7 @@ function processes(callback) {
const parts = line.split(' ');
const command = parts.slice(9).join(' ');
const pmem = parseFloat((1.0 * parseInt(parts[3]) * 1024 / os.totalmem()).toFixed(1));
const elapsed_parts = parts[5].split(':');
const started = formatDateTime(new Date(Date.now() - (elapsed_parts.length > 1 ? (elapsed_parts[0] * 60 + elapsed_parts[1]) * 1000 : elapsed_parts[0] * 1000)));
const started = parseElapsed(parts[5]);
result.push({
pid: parseInt(parts[0]),