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
+17 -3
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]),