Skip to content

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

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

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)

FunctionResult objectLinuxBSDMacWinSunComments
si.diskLayout(cb)[{...}]XXXphysical disk layout (array)
[0].deviceXXe.g. /dev/sda
[0].typeXXXHD, SSD, NVMe
[0].nameXXXdisk name
[0].vendorXXvendor/producer
[0].sizeXXXsize in bytes
[0].totalCylindersXtotal cylinders
[0].totalHeadsXtotal heads
[0].totalTracksXtotal tracks
[0].totalSectorsXtotal sectors
[0].tracksPerCylinderXtracks per cylinder
[0].sectorsPerTrackXsectors per track
[0].bytesPerSectorXbytes per sector
[0].firmwareRevisionXXXfirmware revision
[0].serialNumXXXserial number
[0].interfaceTypeXXXSATA, PCIe, ...
[0].smartStatusXXXS.M.A.R.T Status (see Known Issues)
[0].temperatureXXXS.M.A.R.T temperature (if available)
[0].smartDataXXXfull S.M.A.R.T data from smartctl
requires at least smartmontools 7.0
(see Known Issues)
si.blockDevices(cb)[{...}]XXXreturns array of disks, partitions,
raids and roms
[0].nameXXXname
[0].identifierXXXstable device identifier
[0].typeXXXtype
[0].fsTypeXXXfile system type (e.g. ext4)
[0].mountXXXmount point
[0].sizeXXXsize in bytes
[0].physicalXXXphysical type (HDD, SSD, CD/DVD)
[0].uuidXXXUUID
[0].labelXXXlabel
[0].modelXXmodel
[0].serialXXserial
[0].removableXXXserial
[0].protocolXXprotocol (SATA, PCI-Express, ...)
[0].groupXRaid group member (e.g. md1)
[1].deviceXXXPhysical device mapped to (e.g. /dev/sda)
si.disksIO(cb)XXcurrent transfer stats
rIOXXread IOs on all mounted drives
wIOXXwrite IOs on all mounted drives
tIOXXwrite IOs on all mounted drives
rIO_secXXread IO per sec (* see notes)
wIO_secXXwrite IO per sec (* see notes)
tIO_secXXtotal IO per sec (* see notes)
rWaitTimeXread IO request time
wWaitTimeXwrite IO request time
tWaitTimeXtotal IO request time
rWaitPercentXread IO request time percent
wWaitPercentXwrite IO request time percent
tWaitPercentXtotal IO request time percent
msXXinterval length (for per second values)

File System and File System Stats

FunctionResult objectLinuxBSDMacWinSunComments
si.fsSize(drive, cb)[{...}]XXXXreturns array of mounted file systems
drive parameter is optional
[0].fsXXXXname of file system
[0].typeXXXXtype of file system
[0].sizeXXXXsizes in bytes
[0].usedXXXXused in bytes
[0].availableXXXXavailable in bytes
[0].useXXXXused in %
[0].mountXXXXmount point
[0].rwXXXXRead/Write (false if read only)
si.fsOpenFiles(cb)XXXcount max/allocated file descriptors
maxXXXcount max
allocatedXXXcount allocated
availableXXXcount available
si.fsStats(cb)XXcurrent transfer stats
rxXXbytes read since startup
wxXXbytes written since startup
txXXtotal bytes read + written since startup
rx_secXXbytes read / second (* see notes)
wx_secXXbytes written / second (* see notes)
tx_secXXtotal bytes reads + written / second
msXXinterval length (for per second values)

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('@ambicuity/systeminspector');

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

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

Examples

Example
const si = require('@ambicuity/systeminspector');
si.diskLayout().then(data => console.log(data));
json
[
  {
    device: '/dev/nvme0n1',
    type: 'NVMe',
    name: 'SAMSUNG xxxxxxxxxxxx-xxxx',
    vendor: 'Samsung',
    size: 1024209543168,
    bytesPerSector: null,
    totalCylinders: null,
    totalHeads: null,
    totalSectors: null,
    totalTracks: null,
    tracksPerCylinder: null,
    sectorsPerTrack: null,
    firmwareRevision: '',
    serialNum: '...serial....',
    interfaceType: 'PCIe',
    smartStatus: 'unknown',
    smartData: {
      json_format_version: [Array],
      smartctl: [Object],
      device: [Object],
      model_name: 'SAMSUNG xxxxxxxxxxxx-xxxx',
      serial_number: '...serial....',             // full structure
      ...                                         // see index.d.ts
    }
  },
  {
    ...
  }
]
Example
const si = require('@ambicuity/systeminspector');
si.blockDevices().then(data => console.log(data));
json
[
  {
    name: 'nvme0n1',
    identifier: 'nvme0n1',
    type: 'disk',
    fsType: '',
    mount: '',
    size: 1024209543168,
    physical: 'SSD',
    uuid: '',
    label: '',
    model: 'SAMSUNG xxxxxxxxxxxx-xxxx',
    serial: '... serial ...',
    removable: false,
    protocol: 'nvme',
    group: '',
    device: 'nvme0n1'
  },
  {
    ...
  }
]
Example
const si = require('@ambicuity/systeminspector');
setInterval(function() {
  si.disksIO().then(data => {
    console.log(data);
  })
}, 1000)
json
{                           // first call
  rIO: 899825,
  wIO: 932331,
  tIO: 1832156,
  rIO_sec: null,
  wIO_sec: null,
  tIO_sec: null,
  ms: 0
}
{                           // second call
  rIO: 899863,
  wIO: 932331,
  tIO: 1832194,
  rIO_sec: 38.5395537525355,
  wIO_sec: 0,
  tIO_sec: 38.5395537525355,
  ms: 986
}...
Example
const si = require('@ambicuity/systeminspector');
si.fsSize().then(data => console.log(data));
json
[
  {
    fs: '/dev/md2',
    type: 'ext4',
    size: 972577361920,
    used: 59142635520,
    available: 913434726400,
    use: 6.08,
    mount: '/',
    rw: true
  },
  {
    ...
  }
]
Example
const si = require('@ambicuity/systeminspector');
si.fsOpenFiles().then(data => console.log(data));
json
{
  max: 6566555,
  allocated: 1856,
  available: 0
}
Example
const si = require('@ambicuity/systeminspector');
setInterval(function() {
  si.fsStats().then(data => {
    console.log(data);
  })
}, 1000)
json
{                             // first call
  rx: 14015849472,
  wx: 15316003328,
  tx: 29331852800,
  rx_sec: null,
  wx_sec: null,
  tx_sec: null,
  ms: 0
}
{                             // second call
  rx: 14015849472,
  wx: 15316007424,
  tx: 29331856896,
  rx_sec: 0,
  wx_sec: 4083.748753738784,
  tx_sec: 4083.748753738784,
  ms: 1003
}...
Inspector AI
SystemInspector AI initialized. How can I help you query your hardware?