From c2e9d331183cc17ab9417672d66a242e58de1351 Mon Sep 17 00:00:00 2001 From: tekert Date: Tue, 25 Jul 2023 09:30:29 -0300 Subject: [PATCH] Fix reported Data bytes Read/Written on SSDs This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes written) and is rounded up. When the LBA size is a value other than 512 bytes, the controller shall convert the amount of data written to 512 byte units. Current code is using 1024 instead of 1000. Signed-off-by: tekert --- smartctl.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/smartctl.go b/smartctl.go index 7ffb25e..22049eb 100644 --- a/smartctl.go +++ b/smartctl.go @@ -300,21 +300,25 @@ func (smart *SMARTctl) mineNumErrLogEntries() { } func (smart *SMARTctl) mineBytesRead() { - blockSize := smart.json.Get("logical_block_size").Float() * 1024 + blockSize := smart.json.Get("logical_block_size").Float() smart.ch <- prometheus.MustNewConstMetric( metricDeviceBytesRead, prometheus.CounterValue, - smart.json.Get("nvme_smart_health_information_log.data_units_read").Float()*blockSize, + // This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes written) and is rounded up. + // When the LBA size is a value other than 512 bytes, the controller shall convert the amount of data written to 512 byte units. + smart.json.Get("nvme_smart_health_information_log.data_units_read").Float()*1000.0*blockSize, smart.device.device, ) } func (smart *SMARTctl) mineBytesWritten() { - blockSize := smart.json.Get("logical_block_size").Float() * 1024 + blockSize := smart.json.Get("logical_block_size").Float() smart.ch <- prometheus.MustNewConstMetric( metricDeviceBytesWritten, prometheus.CounterValue, - smart.json.Get("nvme_smart_health_information_log.data_units_written").Float()*blockSize, + // This value is reported in thousands (i.e., a value of 1 corresponds to 1000 units of 512 bytes written) and is rounded up. + // When the LBA size is a value other than 512 bytes, the controller shall convert the amount of data written to 512 byte units. + smart.json.Get("nvme_smart_health_information_log.data_units_written").Float()*1000.0*blockSize, smart.device.device, ) }