lib/processMonitor.js
function format(param, data, cb) {
    const time = util.formatTime(new Date());
    const outArray = data.toString().replace(/^\s+|\s+$/g, '').split(/\s+/);
    let outValueArray = [];
    for (let i = 0; i < outArray.length; i++) {
        if ((!isNaN(outArray[i]))) {
            outValueArray.push(outArray[i]);
        }
    }
    const ps = {};
    ps.time = time;
    ps.serverId = param.serverId;
    ps.serverType = ps.serverId.split('-')[0];
    ps.pid = param.pid;
    const pid = ps.pid;
    ps.cpuAvg = outValueArray[1];
    ps.memAvg = outValueArray[2];
    ps.vsz = outValueArray[3];
    ps.rss = outValueArray[4];
    outValueArray = [];
    if (process.platform === 'darwin') {
        ps.usr = 0;
        ps.sys = 0;
        ps.gue = 0;
        cb(null, ps);
        return;
    }
    exec(`pidstat -p ${pid}`, (err, output) => {
        if (err) {
            console.error('the command pidstat failed! ', err.stack);
            return;
        }
        const _outArray = output.toString().replace(/^\s+|\s+$/g, '').split(/\s+/);
        for (let i = 0; i < _outArray.length; i++) {
            if ((!isNaN(_outArray[i]))) {
                outValueArray.push(_outArray[i]);
            }
        }
        ps.usr = outValueArray[1];
        ps.sys = outValueArray[2];
        ps.gue = outValueArray[3];

        cb(null, ps);
    });
}
function format(param, data, cb) {
    const time = util.formatTime(new Date());
    const outArray = data.toString().replace(/^\s+|\s+$/g, '').split(/\s+/);
    let outValueArray = [];
    for (let i = 0; i < outArray.length; i++) {
        if ((!isNaN(outArray[i]))) {
            outValueArray.push(outArray[i]);
        }
    }
    const ps = {};
    ps.time = time;
    ps.serverId = param.serverId;
    ps.serverType = ps.serverId.split('-')[0];
    ps.pid = param.pid;
    const pid = ps.pid;
    ps.cpuAvg = outValueArray[1];
    ps.memAvg = outValueArray[2];
    ps.vsz = outValueArray[3];
    ps.rss = outValueArray[4];
    outValueArray = [];
    if (process.platform === 'darwin') {
        ps.usr = 0;
        ps.sys = 0;
        ps.gue = 0;
        cb(null, ps);
        return;
    }
    exec(`pidstat -p ${pid}`, (err, output) => {
        if (err) {
            console.error('the command pidstat failed! ', err.stack);
            return;
        }
        const _outArray = output.toString().replace(/^\s+|\s+$/g, '').split(/\s+/);
        for (let i = 0; i < _outArray.length; i++) {
            if ((!isNaN(_outArray[i]))) {
                outValueArray.push(_outArray[i]);
            }
        }
        ps.usr = outValueArray[1];
        ps.sys = outValueArray[2];
        ps.gue = outValueArray[3];

        cb(null, ps);
    });
}
function format ( param , data , cb ) { const time = util . formatTime ( new Date ( ) ) ; const outArray = data . toString ( ) . replace ( / ^\s+|\s+$ / g , '' ) . split ( / \s+ / ) ; let outValueArray = [ ] ; for ( let i = 0 ; i < outArray . length ; i ++ ) { if ( ( ! isNaN ( outArray [ i ] ) ) ) { outValueArray . push ( outArray [ i ] ) ; } } const ps = { } ; ps . time = time ; ps . serverId = param . serverId ; ps . serverType = ps . serverId . split ( '-' ) [ 0 ] ; ps . pid = param . pid ; const pid = ps . pid ; ps . cpuAvg = outValueArray [ 1 ] ; ps . memAvg = outValueArray [ 2 ] ; ps . vsz = outValueArray [ 3 ] ; ps . rss = outValueArray [ 4 ] ; outValueArray = [ ] ; if ( process . platform === 'darwin' ) { ps . usr = 0 ; ps . sys = 0 ; ps . gue = 0 ; cb ( null , ps ) ; return ; } exec ( ` ${ pid } ` , ( err , output ) => { if ( err ) { console . error ( 'the command pidstat failed! ' , err . stack ) ; return ; } const _outArray = output . toString ( ) . replace ( / ^\s+|\s+$ / g , '' ) . split ( / \s+ / ) ; for ( let i = 0 ; i < _outArray . length ; i ++ ) { if ( ( ! isNaN ( _outArray [ i ] ) ) ) { outValueArray . push ( _outArray [ i ] ) ; } } ps . usr = outValueArray [ 1 ] ; ps . sys = outValueArray [ 2 ] ; ps . gue = outValueArray [ 3 ] ; cb ( null , ps ) ; } ) ; }
convert serverInfo to required format, and the callback will handle the serverInfo

@param {Object} param, contains serverId etc
@param {String} data, the output if the command 'ps'
@param {Function} cb
@api private
convert serverInfo to required format and the callback will handle the serverInfo