Diskmanage: extract nvme wearout from smartctl text

extract the info from the line:
Percentage Used: XX%

also adapt the tests

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak
2019-06-04 13:05:27 +02:00
committed by Thomas Lamprecht
parent d0a217f624
commit ea928fd41a
3 changed files with 14 additions and 4 deletions

View File

@ -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;
}
};