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 systeminformation as follows:

    const si = require('systeminformation');

## 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)

Function | Result object | Linux | BSD | Mac | Win | Sun | Comments
--- | --- | --- | --- | --- | --- | --- | ---
si.currentLoad(cb) | {...} | X |  | X | X | X | CPU-Load
| avgload | X |  | X |  | X | average load
| currentload | X |  | X | X | X | CPU load in %
| currentload_user | X |  | X | X | X | CPU load user in %
| currentload_system | X |  | X | X | X | CPU load system in %
| currentload_nice | X |  | X | X | X | CPU load nice in %
| currentload_idle | X |  | X | X | X | CPU load idle in %
| currentload_irq | X |  | X | X | X | CPU load system in %
| raw_currentload... | X |  | X | X | X | CPU load raw values (ticks)
| cpus[] | X |  | X | X | X | current loads per CPU in % + raw ticks
| ##### Example
    const si = require('systeminformation');
    si.currentLoad().then(data => console.log(data));
    {
      avgload: 0.23,
      currentload: 4.326328800988875,
      currentload_user: 2.595797280593325,
      currentload_system: 1.73053152039555,
      currentload_nice: 0,
      currentload_idle: 95.67367119901112,
      currentload_irq: 0,
      raw_currentload: 350,
      raw_currentload_user: 210,
      raw_currentload_system: 140,
      raw_currentload_nice: 0,
      raw_currentload_idle: 7740,
      raw_currentload_irq: 0,
      cpus: [
        {
          load: 13.725490196078432,
          load_user: 7.8431372549019605,
          load_system: 5.88235294117647,
          load_nice: 0,
          load_idle: 86.27450980392157,
          load_irq: 0,
          raw_load: 140,
          raw_load_user: 80,
          raw_load_system: 60,
          raw_load_nice: 0,
          raw_load_idle: 880,
          raw_load_irq: 0
        },
        ...
      ]
    }
si.fullLoad(cb) | : integer | X |  | X | X |  | CPU full load since bootup in %
si.processes(cb) | {...} | X | X | X | X | X | # running processes
| all | X | X | X | X | X | # of all processes
| running | X | X | X | X | X | # of all processes running
| blocked | X | X | X | X | X | # of all processes blocked
| sleeping | X | X | X | X | X | # of all processes sleeping
| unknown |  |  |  | X |  | # of all processes unknown status
| list[] | X | X | X | X | X | list of all processes incl. details
| ...[0].pid | X | X | X | X | X | process PID
| ...[0].parentPid | X | X | X | X | X | parent process PID
| ...[0].name | X | X | X | X | X | process name
| ...[0].pcpu | X | X | X | X | X | process % CPU usage
| ...[0].pcpuu | X | X |  | X |  | process % CPU usage (user)
| ...[0].pcpus | X | X |  | X |  | process % CPU usage (system)
| ...[0].pmem | X | X | X | X | X | process memory %
| ...[0].priority | X | X | X | X | X | process priotity
| ...[0].mem_vsz | X | X | X | X | X | process virtual memory size
| ...[0].mem_rss | X | X | X | X | X | process mem resident set size
| ...[0].nice | X | X | X |  | X | process nice value
| ...[0].started | X | X | X | X | X | process start time
| ...[0].state | X | X | X | X | X | process state (e.g. sleeping)
| ...[0].tty | X | X | X |  | X | tty from which process was started
| ...[0].user | X | X | X |  | X | user who started process
| ...[0].command | X | X | X | X | X | process starting command
| ...[0].params | X | X | X |  | X | process params
| ...[0].path | X | X | X | X | X | process path
| ##### Example
    const si = require('systeminformation');
    si.processes().then(data => console.log(data));
    {
      all: 258,
      running: 1,
      blocked: 0,
      sleeping: 157,
      unknown: 0,
      list: [
        {
          pid: 1,
          parentPid: 0,
          name: 'init',
          pcpu: 0.04504576931569955,
          pcpuu: 0.04084113255431208,
          pcpus: 0.00420463676138747,
          pmem: 0,
          priority: 19,
          mem_vsz: 166144,
          mem_rss: 10684,
          nice: 0,
          started: '2020-02-08 10:18:15',
          state: 'sleeping',
          tty: '',
          user: 'root',
          command: 'init',
          params: '',
          path: '/sbin'
        },
        ...
      ]
    }
si.processLoad('nginx',cb) | {...} | X | X | X | X |  | detailed information about given process
| proc | X | X | X | X |  | process name
| pid | X | X | X | X |  | PID
| pids | X | X | X | X |  | additional pids
| cpu | X | X | X | X |  | process % CPU
| mem | X | X | X | X |  | process % MEM
| ##### Example
    const si = require('systeminformation');
    si.processLoad('nginx').then(data => console.log(data));
    {
      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
    }
si.services('mysql, apache2', cb) | [{...}] | X | X | X | X |  | pass comma separated string of services pass "*" for ALL services (linux/win only)
| [0].name | X | X | X | X |  | name of service
| [0].running | X | X | X | X |  | true / false
| [0].startmode |  |  |  | X |  | manual, automatic, ...
| [0].pids | X | X | X |  |  | pids
| [0].pcpu | X | X | X |  |  | process % CPU
| [0].pmem | X | X | X |  |  | process % MEM
| ##### Example
    const si = require('systeminformation');
    si.services('mysql, postgres').then(data => console.log(data));
    [
      {
        name: 'mysql',
        running: true,
        startmode: '',
        pids: [ 152 ],
        pcpu: 0.3,
        pmem: 0
      },
      {
        name: 'postgres',
        running: true,
        startmode: '',
        pids: [ 1087, 1873 ],
        pcpu: 0,
        pmem: 0
      },
    ]

#### 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('systeminformation');

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

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