Skip to content

Commit c05b97c

Browse files
authored
collector/diskstats: Use SCSI_IDENT_SERIAL as serial (#2612)
On most hard drives, `ID_SERIAL_SHORT` and `SCSI_IDENT_SERIAL` are identical, but on some SAS drives they do differ. In that case, `SCSI_IDENT_SERIAL` corresponds to the serial number printed on the drive label, and to the value returned by `smartctl -i`. So use that value by default for the `serial` label on the `node_disk_info` metric, and fallback to `ID_SERIAL_SHORT` only if it's undefined. Signed-off-by: Benoît Knecht <[email protected]>
1 parent da0b2ca commit c05b97c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

collector/diskstats_linux.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const (
6363
udevIDRevision = "ID_REVISION"
6464
udevIDSerialShort = "ID_SERIAL_SHORT"
6565
udevIDWWN = "ID_WWN"
66+
udevSCSIIdentSerial = "SCSI_IDENT_SERIAL"
6667
)
6768

6869
type typedFactorDesc struct {
@@ -286,13 +287,21 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
286287
level.Debug(c.logger).Log("msg", "Failed to parse udev info", "err", err)
287288
}
288289

290+
// This is usually the serial printed on the disk label.
291+
serial := info[udevSCSIIdentSerial]
292+
293+
// If it's undefined, fallback to ID_SERIAL_SHORT instead.
294+
if serial == "" {
295+
serial = info[udevIDSerialShort]
296+
}
297+
289298
ch <- c.infoDesc.mustNewConstMetric(1.0, dev,
290299
fmt.Sprint(stats.MajorNumber),
291300
fmt.Sprint(stats.MinorNumber),
292301
info[udevIDPath],
293302
info[udevIDWWN],
294303
info[udevIDModel],
295-
info[udevIDSerialShort],
304+
serial,
296305
info[udevIDRevision],
297306
)
298307

0 commit comments

Comments
 (0)