Skip to content

Processes and Services

In this section you will learn how to get information about current load, running processes and installed services:

For function reference and examples we assume, that we imported systeminspector as follows:

const si = require('@ambicuity/systeminspector');

Current Load, Processes, Services

All functions in this section return a promise or can be called with a callback function (parameter cb in the function reference)

FunctionResult objectLinuxBSDMacWinSunComments
si.currentLoad(cb)XXXXCPU-Load
avgLoadXXXaverage load
currentLoadXXXXCPU load in %
currentLoadUserXXXXCPU load user in %
currentLoadSystemXXXXCPU load system in %
currentLoadNiceXXXXCPU load nice in %
currentLoadIdleXXXXCPU load idle in %
currentLoadIrqXXXXCPU load hardware interrupts in %
currentLoadStealXTime stolen by other OS running in VMs in %
currentLoadGuestXTime spent for running virtual CPU in %
rawCurrentLoad...XXXXCPU load raw values (ticks)
cpus\XXXXcurrent loads per CPU in % + raw ticks
si.fullLoad(cb): integerXXXCPU full load since bootup in %
si.processes(cb)XXXXX# running processes
allXXXXX# of all processes
runningXXXX# of all processes running
blockedXXXX# of all processes blocked
sleepingXXXX# of all processes sleeping
unknownX# of all processes unknown status
list\XXXXXlist of all processes incl. details
...[0].pidXXXXXprocess PID
...[0].parentPidXXXXXparent process PID
...[0].nameXXXXXprocess name
...[0].cpuXXXXXprocess % CPU usage
...[0].cpuuXXXprocess % CPU usage (user)
...[0].cpusXXXprocess % CPU usage (system)
...[0].memXXXXXprocess memory %
...[0].priorityXXXXXprocess priority
...[0].memVszXXXXXprocess virtual memory size
...[0].memRssXXXXXprocess mem resident set size
...[0].niceXXXXprocess nice value
...[0].startedXXXXXprocess start time
...[0].stateXXXXXprocess state (e.g. sleeping)
...[0].ttyXXXXtty from which process was started
...[0].userXXXXuser who started process
...[0].commandXXXXXprocess starting command
...[0].paramsXXXXprocess params
...[0].pathXXXXXprocess path
si.processLoad('nginx, ssl',cb)[{...}]XXXXdetailed information about given processes
pass comma separated list or
'*' for all processes
[0].procXXXXprocess name
[0].pidXXXXPID
[0].pidsXXXXadditional pids
[0].cpuXXXXprocess % CPU
[0].memXXXXprocess % MEM
si.services('mysql, apache2', cb)[{...}]XXXXpass comma separated string of services
pass "*" for ALL services (linux/win only)
[0].nameXXXXname of service
[0].runningXXXXtrue / false
[0].startmodeXmanual, automatic, ...
[0].pidsXXXpids
[0].cpuXXXprocess % CPU
[0].memXXXprocess % MEM

Getting correct stats values

In currentLoad() the results are calculated correctly beginning with the second call of the function. It is determined by calculating the difference of cpu ticks between two calls of the function.

The first time you are calling one of this functions, you will get the load since cpu uptime. The second time, you should then get statistics based on cpu ticks between the two calls ...

So basically, your code should look like this:

const si = require('@ambicuity/systeminspector');

              setInterval(function() {
                  si.currentLoad().then(data => {
                      console.log(data);
                  })
              }, 1000)

Beginning with the second call, you get precise load values between the two calls.

Examples

Example
const si = require('@ambicuity/systeminspector');
si.currentLoad().then(data => console.log(data));
json
{
  avgLoad: 0.23,
  currentLoad: 4.326328800988875,
  currentLoadUser: 2.595797280593325,
  currentLoadSystem: 1.73053152039555,
  currentLoadNice: 0,
  currentLoadIdle: 95.67367119901112,
  currentLoadIrq: 0,
  rawCurrentLoad: 350,
  rawCurrentLoadUser: 210,
  rawCurrentLoadSystem: 140,
  rawCurrentLoadNice: 0,
  rawCurrentLoadIdle: 7740,
  rawCurrentLoadIrq: 0,
  rawCurrentLoadSteal: 0,
  rawCurrentLoadGuest: 0,
  cpus: [
    {
      load: 13.725490196078432,
      loadUser: 7.8431372549019605,
      loadSystem: 5.88235294117647,
      loadNice: 0,
      loadIdle: 86.27450980392157,
      loadIrq: 0,
      loadSteal: 0,
      loadGuest: 0,
      rawLoad: 140,
      rawLoadUser: 80,
      rawLoadSystem: 60,
      rawLoadNice: 0,
      rawLoadIdle: 880,
      rawLoadIrq: 0
      rawLoadSteal: 0
      rawLoadGuest: 0
    },
    ...
  ]
}
Example
const si = require('@ambicuity/systeminspector');
si.processes().then(data => console.log(data));
json
{
  all: 258,
  running: 1,
  blocked: 0,
  sleeping: 157,
  unknown: 0,
  list: [
    {
      pid: 1,
      parentPid: 0,
      name: 'init',
      cpu: 0.04504576931569955,
      cpuu: 0.04084113255431208,
      cpus: 0.00420463676138747,
      mem: 0,
      priority: 19,
      memVsz: 166144,
      memRss: 10684,
      nice: 0,
      started: '2020-02-08 10:18:15',
      state: 'sleeping',
      tty: '',
      user: 'root',
      command: 'init',
      params: '',
      path: '/sbin'
    },
    ...
  ]
}
Example
const si = require('@ambicuity/systeminspector');
si.processLoad('nginx, postgres').then(data => console.log(data));
json
[
{
  proc: 'nginx',
  pid: 11267,
  pids: [
    11251, 11252, 11253,
    11254, 11255, 11256,
    11257, 11258, 11259,
    11260, 11261, 11262,
    11263, 11264, 11265,
    11266, 11267
  ],
  cpu: 0.01,
  mem: 0
},
  {
    proc: 'postgres',
    pid: 1435,
    pids: [
      1435, 1513, 1545,
      1546, 1547, 1548,
      1549, 1550
    ],
    cpu: 0.01,
    mem: 0
  },
]
Example
const si = require('@ambicuity/systeminspector');
si.services('mysql, postgres').then(data => console.log(data));
json
[
  {
    name: 'mysql',
    running: true,
    startmode: '',
    pids: [ 152 ],
    cpu: 0.3,
    mem: 0
  },
  {
    name: 'postgres',
    running: true,
    startmode: '',
    pids: [ 1087, 1873 ],
    cpu: 0,
    mem: 0
  },
]
Inspector AI
SystemInspector AI initialized. How can I help you query your hardware?