Skip to content

Commit 556c362

Browse files
committed
diskstats: add fallback to ID_SERIAL for virtio devices
Virtio devices don't have ID_SERIAL_SHORT but do have ID_SERIAL. This change adds a fallback to use ID_SERIAL when ID_SERIAL_SHORT is not available, allowing serial numbers to be properly exposed for virtio block devices. Signed-off-by: Harikrishnan R <me+gh@illustris.tech>
1 parent 6471fa3 commit 556c362

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

collector/diskstats_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060
udevIDModel = "ID_MODEL"
6161
udevIDPath = "ID_PATH"
6262
udevIDRevision = "ID_REVISION"
63+
udevIDSerial = "ID_SERIAL"
6364
udevIDSerialShort = "ID_SERIAL_SHORT"
6465
udevIDWWN = "ID_WWN"
6566
udevSCSIIdentSerial = "SCSI_IDENT_SERIAL"
@@ -294,6 +295,11 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
294295
serial = info[udevIDSerialShort]
295296
}
296297

298+
// If still undefined, fallback to ID_SERIAL (used by virtio devices).
299+
if serial == "" {
300+
serial = info[udevIDSerial]
301+
}
302+
297303
queueStats, err := c.fs.SysBlockDeviceQueueStats(dev)
298304
// Block Device Queue stats may not exist for all devices.
299305
if err != nil && !os.IsNotExist(err) {

0 commit comments

Comments
 (0)