Some nvme devices do not report their capacity through the usual 'user_capacity' field, instead the total capacity is reported with the 'nvme_total_capacity' field. Fixes: #466pull/569/head
parent
a3dfce3561
commit
db86bac9ef
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"json_format_version": [
|
||||||
|
1,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"smartctl": {
|
||||||
|
"version": [
|
||||||
|
7,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"svn_revision": "5155",
|
||||||
|
"platform_info": "x86_64-linux-6.1.69-talos",
|
||||||
|
"build_info": "(local build)",
|
||||||
|
"argv": [
|
||||||
|
"smartctl",
|
||||||
|
"--info",
|
||||||
|
"--json",
|
||||||
|
"/dev/nvme4"
|
||||||
|
],
|
||||||
|
"exit_status": 0
|
||||||
|
},
|
||||||
|
"device": {
|
||||||
|
"name": "/dev/nvme4",
|
||||||
|
"info_name": "/dev/nvme4",
|
||||||
|
"type": "nvme",
|
||||||
|
"protocol": "NVMe"
|
||||||
|
},
|
||||||
|
"model_name": "KCD61LUL3T84",
|
||||||
|
"serial_number": "61Q0A05UT7B8",
|
||||||
|
"firmware_version": "8002",
|
||||||
|
"nvme_pci_vendor": {
|
||||||
|
"id": 7695,
|
||||||
|
"subsystem_id": 7695
|
||||||
|
},
|
||||||
|
"nvme_ieee_oui_identifier": 9233294,
|
||||||
|
"nvme_total_capacity": 3840755982336,
|
||||||
|
"nvme_unallocated_capacity": 0,
|
||||||
|
"nvme_controller_id": 1,
|
||||||
|
"nvme_version": {
|
||||||
|
"string": "1.4",
|
||||||
|
"value": 66560
|
||||||
|
},
|
||||||
|
"nvme_number_of_namespaces": 16,
|
||||||
|
"local_time": {
|
||||||
|
"time_t": 1706045146,
|
||||||
|
"asctime": "Tue Jan 23 21:25:46 2024 UTC"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSmartInfo_Capacity(t *testing.T) {
|
||||||
|
t.Run("should report nvme capacity", func(t *testing.T) {
|
||||||
|
smartInfo := SmartInfo{
|
||||||
|
UserCapacity: UserCapacity{
|
||||||
|
Bytes: 1234,
|
||||||
|
},
|
||||||
|
NvmeTotalCapacity: 5678,
|
||||||
|
}
|
||||||
|
assert.Equal(t, int64(5678), smartInfo.Capacity())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should report user capacity", func(t *testing.T) {
|
||||||
|
smartInfo := SmartInfo{
|
||||||
|
UserCapacity: UserCapacity{
|
||||||
|
Bytes: 1234,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.Equal(t, int64(1234), smartInfo.Capacity())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should report 0 for unknown capacities", func(t *testing.T) {
|
||||||
|
var smartInfo SmartInfo
|
||||||
|
assert.Zero(t, smartInfo.Capacity())
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in new issue