]> git.proxmox.com Git - pve-storage.git/commitdiff
Diskmanage: extract nvme wearout from smartctl text
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 4 Jun 2019 11:05:27 +0000 (13:05 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 14 Jun 2019 08:07:46 +0000 (10:07 +0200)
extract the info from the line:
Percentage Used: XX%

also adapt the tests

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
(cherry picked from commit ea928fd41ab09128bd3ef37c65da1eb3fc96dc78)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Diskmanage.pm
test/disk_tests/nvme_smart/disklist_expected.json
test/disk_tests/nvme_smart/nvme0n1_smart_expected.json

index de3e60e02146fc841826a491353127e3e088e29d..6b2fe1fdf7aceede7f285a2f7dc4d4c0d2642918 100644 (file)
@@ -130,6 +130,10 @@ sub get_smart_data {
            } elsif (defined($type) && $type eq 'text') {
                $smartdata->{text} = '' if !defined $smartdata->{text};
                $smartdata->{text} .= "$line\n";
+               # extract wearout from nvme text, allow for decimal values
+               if ($line =~ m/Percentage Used:.*(\d+(?:\.\d+)?)\%/i) {
+                   $smartdata->{wearout} = 100 - $1;
+               }
            } elsif ($line =~ m/SMART Disabled/) {
                $smartdata->{health} = "SMART Disabled";
            }
@@ -320,7 +324,12 @@ sub get_sysdir_info {
 }
 
 sub get_wear_leveling_info {
-    my ($attributes, $model) = @_;
+    my ($smartdata, $model) = @_;
+    my $attributes = $smartdata->{attributes};
+
+    if (defined($smartdata->{wearout})) {
+       return $smartdata->{wearout};
+    }
 
     my $wearout;
 
@@ -462,7 +471,7 @@ sub get_disks {
 
                if ($type eq 'ssd') {
                    # if we have an ssd we try to get the wearout indicator
-                   my $wearval = get_wear_leveling_info($smartdata->{attributes}, $data->{model} || $sysdir->{model});
+                   my $wearval = get_wear_leveling_info($smartdata, $data->{model} || $sysdir->{model});
                    $wearout = $wearval if $wearval;
                }
            };
index e50e4a35cd7deb9d03556c51a1fbe62b73f67c30..0b043b1437ce83fbc5e85610f29755988879ce07 100644 (file)
@@ -1,6 +1,6 @@
 {
     "nvme0n1" : {
-       "wearout" : "N/A",
+       "wearout" : 100,
        "vendor" : "unknown",
        "size" : 512000,
        "health" : "PASSED",
index 00bece26658a0909fc90959656f748e7a38a67e8..6ea2d678192a3450df35e5e157afa4596e6a1d11 100644 (file)
@@ -1,5 +1,6 @@
 {
     "text" : "\nSMART/Health Information (NVMe Log 0x02, NSID 0xffffffff)\nCritical Warning:                   0x00\nTemperature:                        32 Celsius\nAvailable Spare:                    100%\nAvailable Spare Threshold:          10%\nPercentage Used:                    0%\nData Units Read:                    1,299,288 [665 GB]\nData Units Written:                 5,592,478 [2.86 TB]\nHost Read Commands:                 30,360,807\nHost Write Commands:                470,356,196\nController Busy Time:               12\nPower Cycles:                       98\nPower On Hours:                     687\nUnsafe Shutdowns:                   21\nMedia and Data Integrity Errors:    0\nError Information Log Entries:      0\n",
     "health" : "PASSED",
-    "type" : "text"
+    "type" : "text",
+    "wearout": 100
 }