processes() improved started dt/time parsing (mac OS)
This commit is contained in:
parent
577ce3b825
commit
1a2667e154
@ -88,6 +88,26 @@ function parseTimeUnix(time) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseElapsedTime(etime) {
|
||||
let current = new Date();
|
||||
current = new Date(current.getTime() - current.getTimezoneOffset() * 60000);
|
||||
|
||||
const elapsed = etime.split('-');
|
||||
|
||||
const timeIndex = elapsed.length - 1;
|
||||
const days = timeIndex > 0 ? parseInt(elapsed[timeIndex - 1]) : 0;
|
||||
|
||||
const timeStr = elapsed[timeIndex].split(':');
|
||||
const hours = parseInt(timeStr[0] || 0);
|
||||
const mins = parseInt(timeStr[1] || 0);
|
||||
const secs = parseInt(timeStr[2] || 0);
|
||||
|
||||
const ms = (((((days * 24 + hours) * 60) + mins) * 60 + secs) * 1000);
|
||||
|
||||
const res = new Date(current.getTime() - (((((days * 24 + hours) * 60) + mins) * 60 + secs) * 1000));
|
||||
return res.toISOString().substring(0, 10) + ' ' + res.toISOString().substring(11, 19);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// PS - services
|
||||
// pass a comma separated string with services to check (mysql, apache, postgresql, ...)
|
||||
@ -550,7 +570,7 @@ function processes(callback) {
|
||||
checkColumn(7);
|
||||
const nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
|
||||
checkColumn(8);
|
||||
const started = parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
|
||||
const started = _darwin ? parseElapsedTime(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim()) : parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
|
||||
checkColumn(9);
|
||||
let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim();
|
||||
state = (state[0] === 'R' ? 'running' : (state[0] === 'S' ? 'sleeping' : (state[0] === 'T' ? 'stopped' : (state[0] === 'W' ? 'paging' : (state[0] === 'X' ? 'dead' : (state[0] === 'Z' ? 'zombie' : ((state[0] === 'D' || state[0] === 'U') ? 'blocked' : 'unknown')))))));
|
||||
@ -695,7 +715,7 @@ function processes(callback) {
|
||||
if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
|
||||
if (_linux) { cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,lstart:30,state:5,tty:15,user:20,command; unset LC_ALL'; }
|
||||
if (_freebsd || _openbsd || _netbsd) { cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,lstart,state,tty,user,command; unset LC_ALL'; }
|
||||
if (_darwin) { cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=xxx_fake_title,rss=fake_title2,nice,lstart,state,tty,user,command -r'; }
|
||||
if (_darwin) { cmd = 'ps -axo pid,ppid,pcpu,pmem,pri,vsz=temp_title_1,rss=temp_title_2,nice,etime=temp_title_3,state,tty,user,command -r'; }
|
||||
if (_sunos) { cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; }
|
||||
exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
|
||||
if (!error && stdout.toString().trim()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user