зеркало из https://github.com/microsoft/StorScore.git
183 строки
4.3 KiB
Perl
183 строки
4.3 KiB
Perl
# StorScore
|
|
#
|
|
# Copyright (c) Microsoft Corporation
|
|
#
|
|
# All rights reserved.
|
|
#
|
|
# MIT License
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
# copy of this software and associated documentation files (the "Software"),
|
|
# to deal in the Software without restriction, including without limitation
|
|
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
# and/or sell copies of the Software, and to permit persons to whom the
|
|
# Software is furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
# DEALINGS IN THE SOFTWARE.
|
|
|
|
package StorageToolParser;
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Moose;
|
|
use Util;
|
|
use DeviceDB;
|
|
|
|
|
|
my @extract_rules_smart_info =
|
|
(
|
|
#ToDo: modify StorageTool to print out this information
|
|
#in a more easily parsable format
|
|
{
|
|
match => qr/Model Family:\s+(.+)/,
|
|
store => 'Model Family'
|
|
},
|
|
{
|
|
match => qr/Device Model:\s+(.+)/,
|
|
store => 'Device Model'
|
|
},
|
|
{
|
|
match => qr/Serial Number:\s+(.+)/,
|
|
store => 'Serial Number'
|
|
},
|
|
{
|
|
match => qr/Firmware Version:\s+(.+)/,
|
|
store => 'Firmware Version'
|
|
},
|
|
{
|
|
match => qr/User Capacity:\s+([\d,]+) bytes/,
|
|
store => 'User Capacity (B)'
|
|
},
|
|
{
|
|
match => qr/Disk #\d+\s+:\s+\[(\S+)\s+\]/,
|
|
store => 'Protocol Version'
|
|
},
|
|
);
|
|
|
|
my @extract_rules_log_entries =
|
|
(
|
|
{
|
|
match => qr/Composite Temperature:\s+(.+)/,
|
|
store => 'Composite Temperature'
|
|
},
|
|
{
|
|
match => qr/Data Read \(MB\):\s+(.+)/,
|
|
store => 'Data Read (MB)'
|
|
},
|
|
{
|
|
match => qr/Data Written \(MB\):\s+(.+)/,
|
|
store => 'Host Writes'
|
|
},
|
|
{
|
|
match => qr/Power Cycle Count:\s+(.+)/,
|
|
store => 'Power Cycle Count'
|
|
},
|
|
{
|
|
match => qr/Power On Hours:\s+(.+)/,
|
|
store => 'Power On Hours'
|
|
},
|
|
{
|
|
match => qr/Unsafe Shutdown Count:\s+(.+)/,
|
|
store => 'Unsafe Shutdown Count'
|
|
},
|
|
{
|
|
match => qr/Media Error Count:\s+(.+)/,
|
|
store => 'Media Error Count'
|
|
},
|
|
{
|
|
match => qr/Media Units Written \(MB\):\s+(.+)/,
|
|
store => 'Controller Writes'
|
|
},
|
|
{
|
|
match => qr/Wear Range Delta:\s+(.+)/,
|
|
store => 'Wear Range'
|
|
},
|
|
{
|
|
match => qr/Number of IOs Not Aligned to 4kB Boundaries:\s+(.+)/,
|
|
store => 'Unaligned IOs'
|
|
},
|
|
{
|
|
match => qr/Mapped LBA Count:\s+(.+)/,
|
|
store => 'Mapped LBA Count'
|
|
},
|
|
);
|
|
|
|
sub post_process($)
|
|
{
|
|
my $stats_ref = shift;
|
|
|
|
if ( $stats_ref->{'User Capacity (B)'} )
|
|
{
|
|
# Remove commas: 123,456,789 --> 123456789
|
|
$stats_ref->{'User Capacity (B)'} =~ s/,//g;
|
|
|
|
$stats_ref->{'User Capacity (GB)'} =
|
|
int( $stats_ref->{'User Capacity (B)'} / BYTES_PER_GB_BASE10 );
|
|
}
|
|
}
|
|
|
|
# Parse the "information section" as generated by smartctl.exe -i
|
|
sub parse_info($$)
|
|
{
|
|
my $self = shift;
|
|
|
|
my $stats_ref = shift;
|
|
my $file_name = shift;
|
|
|
|
open my $FILE, '<', $file_name
|
|
or die "Error opening $file_name";
|
|
|
|
while( my $line = <$FILE> )
|
|
{
|
|
do_simple_extract( $line, $stats_ref, \@extract_rules_smart_info );
|
|
}
|
|
|
|
post_process( $stats_ref );
|
|
|
|
close $FILE;
|
|
}
|
|
|
|
sub parse_attributes($$$)
|
|
{
|
|
my $self = shift;
|
|
|
|
my $file_name = shift;
|
|
my $suffix = shift;
|
|
my $stats_ref = shift;
|
|
|
|
return 0 unless -e $file_name;
|
|
|
|
open( my $LOG, '<', "$file_name" ) or do
|
|
{
|
|
warn "Error opening $file_name\n";
|
|
return;
|
|
};
|
|
|
|
while( my $line = <$LOG> )
|
|
{
|
|
do_simple_extract(
|
|
$line,
|
|
$stats_ref,
|
|
\@extract_rules_log_entries,
|
|
suffix => $suffix );
|
|
}
|
|
|
|
post_process( $stats_ref );
|
|
|
|
close $LOG;
|
|
}
|
|
|
|
no Moose;
|
|
__PACKAGE__->meta->make_immutable;
|
|
|
|
1;
|