[pve-devel] [PATCH storage 1/3] Diskmanage: extract nvme wearout from smartctl text
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 4 13:05:27 CEST 2019
extract the info from the line:
Percentage Used: XX%
also adapt the tests
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/Diskmanage.pm | 13 +++++++++++--
test/disk_tests/nvme_smart/disklist_expected.json | 2 +-
test/disk_tests/nvme_smart/nvme0n1_smart_expected.json | 3 ++-
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index 5e33747..fbb0341 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -131,6 +131,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";
}
@@ -352,7 +356,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;
@@ -502,7 +511,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;
}
};
diff --git a/test/disk_tests/nvme_smart/disklist_expected.json b/test/disk_tests/nvme_smart/disklist_expected.json
index e50e4a3..0b043b1 100644
--- a/test/disk_tests/nvme_smart/disklist_expected.json
+++ b/test/disk_tests/nvme_smart/disklist_expected.json
@@ -1,6 +1,6 @@
{
"nvme0n1" : {
- "wearout" : "N/A",
+ "wearout" : 100,
"vendor" : "unknown",
"size" : 512000,
"health" : "PASSED",
diff --git a/test/disk_tests/nvme_smart/nvme0n1_smart_expected.json b/test/disk_tests/nvme_smart/nvme0n1_smart_expected.json
index 00bece2..6ea2d67 100644
--- a/test/disk_tests/nvme_smart/nvme0n1_smart_expected.json
+++ b/test/disk_tests/nvme_smart/nvme0n1_smart_expected.json
@@ -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
}
--
2.11.0
More information about the pve-devel
mailing list