14 Discovery of block devices

Overview

It is possible to discover block devices and their properties:

  • block device name and type
  • device identifiers and properties such as path, model, serial number, WWN, and block sizes
  • partition information
  • block device statistics

To do that, you may use a combination of:

  • the vfs.dev.get item as the master item
  • a dependent low-level discovery rule
  • dependent item prototypes

Configuration

Master item

Create a Zabbix agent item using the following key:

vfs.dev.get[device_stats,.*]

Set the type of information to Text for possibly big JSON data.

History can be disabled for this item, as it is used only as a master item. A relatively short update interval, for example 1m, may be configured to poll the data frequently.

The data returned by this item will contain something like the following for a block device:

{
  "config": [
    {
      "name": "sda",
      "devid": "ata-ST1000LM024_HN-M101MBB_S2R8NX0J123456",
      "type": "disk",
      "size_bytes": 1000204886016
    },
    {
      "name": "sda1",
      "devid": "ata-ST1000LM024_HN-M101MBB_S2R8NX0J123456-part1",
      "type": "partition",
      "size_bytes": 536870912
    }
  ],
  "values": [
    {
      "name": "sda",
      "stats": {
        "reads_completed": 1284,
        "writes_completed": 312,
        "bytes_read": 104857600,
        "bytes_written": 16777216,
        "io_time_ms": 204
      }
    },
    {
      "name": "sda1",
      "stats": {
        "reads_completed": 12,
        "writes_completed": 3,
        "bytes_read": 1048576,
        "bytes_written": 262144,
        "io_time_ms": 8
      }
    }
  ]
}

The config array contains block device inventory and metadata, which usually changes infrequently. The values array contains block device statistics, which are updated on each poll.

Dependent LLD rule

Create a low-level discovery rule as Dependent item type:

As master item select the vfs.dev.get item we created.

In the Preprocessing tab add a JSONPath step with $.config parameter. To avoid unnecessary LLD execution, add a Discard unchanged with heartbeat step with a reasonably large heartbeat, for example 1h. This allows the master item to be polled frequently while low-level discovery is run only when the config changes or when the heartbeat period expires:

In the LLD macros tab define custom macros with the corresponding JSONPath.

For example, when using vfs.dev.get[device_stats,.*], the following JSONPath expressions can be used:

{#DEVNAME} - $.name

In the Filters tab you may add a regular expression that filters only disk devices.

Dependent item prototype

Create an item prototype with Dependent item type in this LLD rule. As master item for these prototypes select the vfs.dev.get item we created.

Note the use of custom macros in the item prototype name and key. The key in this example are custom and user-defined.

  • Name: Size of block device {#DEVNAME}
  • Key: dev.block.size[{#DEVNAME}]

As type of information, use Numeric (unsigned).

In the item prototype Preprocessing tab select JSONPath and use the following JSONPath expression as a parameter:

$.config[?(@.name=='{#DEVNAME}')].size_bytes.first()

Additional item prototypes may be created in the same way, for example:

  • Name: Read bytes on {#DEVNAME}
  • Key: dev.block.read_bytes[{#DEVNAME}]
  • Preprocessing: JSONPath $.values[?(@.name=='{#DEVNAME}')].stats.bytes_read.first()
  • Name: I/O time on {#DEVNAME}
  • Key: dev.block.io_time_ms[{#DEVNAME}]
  • Preprocessing: JSONPath $.values[?(@.name=='{#DEVNAME}')].stats.io_time_ms.first()

When discovery starts, one item per each block device will be created.