processes() fix command line parsing (win) wip
This commit is contained in:
parent
1ef846c4ee
commit
1512eabec1
@ -934,40 +934,32 @@ function processes(callback) {
|
|||||||
try {
|
try {
|
||||||
util
|
util
|
||||||
.powerShell(
|
.powerShell(
|
||||||
'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | fl'
|
'Get-CimInstance Win32_Process | select-Object ProcessId,ParentProcessId,ExecutionState,Caption,CommandLine,ExecutablePath,UserModeTime,KernelModeTime,WorkingSetSize,Priority,PageFileUsage, @{n="CreationDate";e={$_.CreationDate.ToString("yyyy-MM-dd HH:mm:ss")}} | ConvertTo-Json -compress'
|
||||||
)
|
)
|
||||||
.then((stdout, error) => {
|
.then((stdout, error) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let processSections = stdout.split(/\n\s*\n/);
|
const procs = [];
|
||||||
let procs = [];
|
const procStats = [];
|
||||||
let procStats = [];
|
const list_new = {};
|
||||||
let list_new = {};
|
|
||||||
let allcpuu = 0;
|
let allcpuu = 0;
|
||||||
let allcpus = 0;
|
let allcpus = 0;
|
||||||
processSections.forEach((element) => {
|
let processArray = [];
|
||||||
|
try {
|
||||||
|
stdout = stdout.trim().replace(/^\uFEFF/, '');
|
||||||
|
processArray = JSON.parse(stdout);
|
||||||
|
} catch {}
|
||||||
|
processArray.forEach((element) => {
|
||||||
if (element.trim() !== '') {
|
if (element.trim() !== '') {
|
||||||
let lines = element.trim().split('\r\n');
|
const pid = element.ProcessId;
|
||||||
let pid = parseInt(util.getValue(lines, 'ProcessId', ':', true), 10);
|
const parentPid = element.ParentProcessId;
|
||||||
let parentPid = parseInt(util.getValue(lines, 'ParentProcessId', ':', true), 10);
|
const statusValue = element.ExecutionState || null;
|
||||||
let statusValue = util.getValue(lines, 'ExecutionState', ':');
|
const name = element.Caption;
|
||||||
let name = util.getValue(lines, 'Caption', ':', true);
|
const commandLine = element.CommandLine;
|
||||||
let commandLine = util.getValue(lines, 'CommandLine', ':', true);
|
|
||||||
// get additional command line data
|
// get additional command line data
|
||||||
let additionalCommand = false;
|
const commandPath = element.ExecutablePath;
|
||||||
lines.forEach((line) => {
|
const utime = element.UserModeTime;
|
||||||
if (additionalCommand && line.toLowerCase().startsWith(' ')) {
|
const stime = element.KernelModeTime;
|
||||||
commandLine += ' ' + line.trim();
|
const memw = element.WorkingSetSize;
|
||||||
} else {
|
|
||||||
additionalCommand = false;
|
|
||||||
}
|
|
||||||
if (line.toLowerCase().startsWith('commandline')) {
|
|
||||||
additionalCommand = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let commandPath = util.getValue(lines, 'ExecutablePath', ':', true);
|
|
||||||
let utime = parseInt(util.getValue(lines, 'UserModeTime', ':', true), 10);
|
|
||||||
let stime = parseInt(util.getValue(lines, 'KernelModeTime', ':', true), 10);
|
|
||||||
let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
|
|
||||||
allcpuu = allcpuu + utime;
|
allcpuu = allcpuu + utime;
|
||||||
allcpus = allcpus + stime;
|
allcpus = allcpus + stime;
|
||||||
result.all++;
|
result.all++;
|
||||||
@ -997,12 +989,12 @@ function processes(callback) {
|
|||||||
cpuu: 0,
|
cpuu: 0,
|
||||||
cpus: 0,
|
cpus: 0,
|
||||||
mem: (memw / os.totalmem()) * 100,
|
mem: (memw / os.totalmem()) * 100,
|
||||||
priority: parseInt(util.getValue(lines, 'Priority', ':', true), 10),
|
priority: element.Priority | null,
|
||||||
memVsz: parseInt(util.getValue(lines, 'PageFileUsage', ':', true), 10),
|
memVsz: element.PageFileUsage || null,
|
||||||
memRss: Math.floor(parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10) / 1024),
|
memRss: Math.floor((element.WorkingSetSize || 0) / 1024),
|
||||||
nice: 0,
|
nice: 0,
|
||||||
started: util.getValue(lines, 'CreationDate', ':', true),
|
started: element.CreationDate,
|
||||||
state: !statusValue ? _winStatusValues[0] : _winStatusValues[statusValue],
|
state: statusValue ? _winStatusValues[statusValue] : _winStatusValues[0],
|
||||||
tty: '',
|
tty: '',
|
||||||
user: '',
|
user: '',
|
||||||
command: commandLine || name,
|
command: commandLine || name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user