systeminformation

Disks and File System

In this section you will learn how to get disks information, file system information, disk I/O stats and file system stats:

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

    const si = require('systeminformation');

## Disk Layout, Block Devices and Disks IO

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.diskLayout(cb) | [{...}] | X |  | X | X |  | physical disk layout (array)
| [0].device | X |  | X |  |  | e.g. /dev/sda
| [0].type | X |  | X | X |  | HD, SSD, NVMe
| [0].name | X |  | X | X |  | disk name
| [0].vendor | X |  |  | X |  | vendor/producer
| [0].size | X |  | X | X |  | size in bytes
| [0].totalCylinders |  |  |  | X |  | total cylinders
| [0].totalHeads |  |  |  | X |  | total heads
| [0].totalTracks |  |  |  | X |  | total tracks
| [0].totalSectors |  |  |  | X |  | total sectors
| [0].tracksPerCylinder |  |  |  | X |  | tracks per cylinder
| [0].sectorsPerTrack |  |  |  | X |  | sectors per track
| [0].bytesPerSector |  |  |  | X |  | bytes per sector
| [0].firmwareRevision | X |  | X | X |  | firmware revision
| [0].serialNum | X |  | X | X |  | serial number
| [0].interfaceType | X |  |  | X |  | SATA, PCIe, ...
| [0].smartStatus | X |  | X | X |  | S.M.A.R.T Status (see Known Issues)
| [0].smartData | X |  |  |  |  | full S.M.A.R.T data from smartctl requires at least smartmontools 7.0 (see Known Issues)
| ##### Example
    const si = require('systeminformation');
    si.diskLayout().then(data => console.log(data));
    [
      {
        device: '/dev/nvme0n1',
        type: 'NVMe',
        name: 'SAMSUNG xxxxxxxxxxxx-xxxx',
        vendor: 'Samsung',
        size: 1024209543168,
        bytesPerSector: -1,
        totalCylinders: -1,
        totalHeads: -1,
        totalSectors: -1,
        totalTracks: -1,
        tracksPerCylinder: -1,
        sectorsPerTrack: -1,
        firmwareRevision: '',
        serialNum: '...serial....',
        interfaceType: 'PCIe',
        smartStatus: 'unknown',
        smartData: {
          json_format_version: [Array],
          smartctl: [Object],
          device: [Object],
          model_name: 'SAMSUNG xxxxxxxxxxxx-xxxx',
          serial_number: '...serial....',
          ...
        }
      },
      {
        ...
      }
    ]
si.blockDevices(cb) | [{...}] | X |  | X | X |  | returns array of disks, partitions, raids and roms
| [0].name | X |  | X | X |  | name
| [0].type | X |  | X | X |  | type
| [0].fstype | X |  | X | X |  | file system type (e.g. ext4)
| [0].mount | X |  | X | X |  | mount point
| [0].size | X |  | X | X |  | size in bytes
| [0].physical | X |  | X | X |  | physical type (HDD, SSD, CD/DVD)
| [0].uuid | X |  | X | X |  | UUID
| [0].label | X |  | X | X |  | label
| [0].model | X |  | X |  |  | model
| [0].serial | X |  |  | X |  | serial
| [0].removable | X |  | X | X |  | serial
| [0].protocol | X |  | X |  |  | protocol (SATA, PCI-Express, ...)
| ##### Example
    const si = require('systeminformation');
    si.blockDevices().then(data => console.log(data));
    [
      {
        name: 'nvme0n1',
        type: 'disk',
        fstype: '',
        mount: '',
        size: 1024209543168,
        physical: 'SSD',
        uuid: '',
        label: '',
        model: 'SAMSUNG xxxxxxxxxxxx-xxxx',
        serial: '... serial ...',
        removable: false,
        protocol: 'nvme',
        group: undefined
      },
      {
        ...
      }
    ]
si.disksIO(cb) | {...} | X |  | X |  |  | current transfer stats
| rIO | X |  | X |  |  | read IOs on all mounted drives
| wIO | X |  | X |  |  | write IOs on all mounted drives
| tIO | X |  | X |  |  | write IOs on all mounted drives
| rIO_sec | X |  | X |  |  | read IO per sec (* see notes)
| wIO_sec | X |  | X |  |  | write IO per sec (* see notes)
| tIO_sec | X |  | X |  |  | total IO per sec (* see notes)
| ms | X |  | X |  |  | interval length (for per second values)
| ##### Example
    const si = require('systeminformation');
    setInterval(function() {
      si.disksIO().then(data => {
        console.log(data);
      })
    }, 1000)
    {                           // first call
      rIO: 899825,
      wIO: 932331,
      tIO: 1832156,
      rIO_sec: -1,
      wIO_sec: -1,
      tIO_sec: -1,
      ms: 0
    }
    {                           // second call
      rIO: 899863,
      wIO: 932331,
      tIO: 1832194,
      rIO_sec: 38.5395537525355,
      wIO_sec: 0,
      tIO_sec: 38.5395537525355,
      ms: 986
    }...

## File System and File System Stats

Function | Result object | Linux | BSD | Mac | Win | Sun | Comments
--- | --- | --- | --- | --- | --- | --- | ---
si.fsSize(cb) | [{...}] | X | X | X | X |  | returns array of mounted file systems
| [0].fs | X | X | X | X |  | name of file system
| [0].type | X | X | X | X |  | type of file system
| [0].size | X | X | X | X |  | sizes in bytes
| [0].used | X | X | X | X |  | used in bytes
| [0].use | X | X | X | X |  | used in %
| [0].mount | X | X | X | X |  | mount point
| ##### Example
    const si = require('systeminformation');
    si.fsSize().then(data => console.log(data));
    [
      {
        fs: '/dev/md2',
        type: 'ext4',
        size: 972577361920,
        used: 59142635520,
        use: 6.08,
        mount: '/'
      },
      {
        ...
      }
    ]
si.fsOpenFiles(cb) | {...} | X | X | X |  |  | count max/allocated file descriptors
| max | X | X | X |  |  | count max
| allocated | X | X | X |  |  | count allocated
| available | X | X | X |  |  | count available
| ##### Example
    const si = require('systeminformation');
    si.fsOpenFiles().then(data => console.log(data));
    {
      max: 6566555,
      allocated: 1856,
      available: 0
    }
si.fsStats(cb) | {...} | X |  | X |  |  | current transfer stats
| rx | X |  | X |  |  | bytes read since startup
| wx | X |  | X |  |  | bytes written since startup
| tx | X |  | X |  |  | total bytes read + written since startup
| rx_sec | X |  | X |  |  | bytes read / second (* see notes)
| wx_sec | X |  | X |  |  | bytes written / second (* see notes)
| tx_sec | X |  | X |  |  | total bytes reads + written / second
| ms | X |  | X |  |  | interval length (for per second values)
| ##### Example
    const si = require('systeminformation');
    setInterval(function() {
      si.fsStats().then(data => {
        console.log(data);
      })
    }, 1000)
    {                             // first call
      rx: 14015849472,
      wx: 15316003328,
      tx: 29331852800,
      rx_sec: -1,
      wx_sec: -1,
      tx_sec: -1,
      ms: 0
    }
    {                             // second call
      rx: 14015849472,
      wx: 15316007424,
      tx: 29331856896,
      rx_sec: 0,
      wx_sec: 4083.748753738784,
      tx_sec: 4083.748753738784,
      ms: 1003
    }...

#### Getting correct stats values

In disksIO() and fsStats() the results / sec. values (rx_sec, IOPS, ...) are calculated correctly beginning with the second call of the function. It is determined by calculating the difference of transferred bytes / IOs divided by the time between two calls of the function.

The first time you are calling one of this functions, you will get -1 for transfer rates. The second time, you should then get statistics based on the time between the two calls ...

So basically, if you e.g. need a values for filesystem stats stats every second, your code should look like this:

    const si = require('systeminformation');

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

Beginning with the second call, you get file system transfer values per second.