README.pod 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. =head1 NAME
  2. Disk::SMART - Provides an interface to smartctl to return disk stats and to run tests.
  3. =head1 SYNOPSIS
  4. Disk::SMART is an object oriented module that provides an interface to get SMART disk info from a device as well as initiate testing. An exmple script using this module can be found at https://github.com/paultrost/linux-geek/blob/master/sysinfo.pl
  5. use Disk::SMART;
  6. my $smart = Disk::SMART->new('/dev/sda', '/dev/sdb');
  7. my $disk_health = $smart->get_disk_health('/dev/sda');
  8. =head1 CONSTRUCTOR
  9. =head2 B<new(DEVICE)>
  10. Instantiates the Disk::SMART object
  11. C<DEVICE> - Device identifier of a single SSD / Hard Drive, or a list. If no devices are supplied then it runs get_disk_list() which will return an array of detected sdX and hdX devices.
  12. my $smart = Disk::SMART->new();
  13. my $smart = Disk::SMART->new( '/dev/sda', '/dev/sdb' );
  14. my @disks = $smart->get_disk_list();
  15. Returns C<Disk::SMART> object if smartctl is available and can poll the given device(s).
  16. =head1 USER METHODS
  17. =head2 B<get_disk_attributes(DEVICE)>
  18. Returns hash of the SMART disk attributes and values
  19. C<DEVICE> - Device identifier of a single SSD / Hard Drive
  20. my %disk_attributes = $smart->get_disk_attributes('/dev/sda');
  21. =head2 B<get_disk_errors(DEVICE)>
  22. Returns scalar of any listed errors
  23. C<DEVICE> - Device identifier of a single SSD/ Hard Drive
  24. my $disk_errors = $smart->get_disk_errors('/dev/sda');
  25. =head2 B<get_disk_health(DEVICE)>
  26. Returns the health of the disk. Output is "PASSED", "FAILED", or "N/A". If the device has positive values for the attributes listed below then the status will output that information.
  27. Eg. "FAILED - Reported_Uncorrectable_Errors = 1"
  28. The attributes are:
  29. 5 - Reallocated_Sector_Count
  30. 187 - Reported_Uncorrectable_Errors
  31. 188 - Command_Timeout
  32. 197 - Current_Pending_Sector_Count
  33. 198 - Offline_Uncorrectable
  34. If Reported_Uncorrectable_Errors is greater than 0 then the drive should be replaced immediately. This list is taken from a study shown at https://www.backblaze.com/blog/hard-drive-smart-stats/
  35. C<DEVICE> - Device identifier of a single SSD / Hard Drive
  36. my $disk_health = $smart->get_disk_health('/dev/sda');
  37. =head2 B<get_disk_list>
  38. Returns list of detected hda and sda devices. This method can be called manually if unsure what devices are present.
  39. $smart->get_disk_list;
  40. =head2 B<get_disk_model(DEVICE)>
  41. Returns the model of the device. eg. "ST3250410AS".
  42. C<DEVICE> - Device identifier of a single SSD / Hard Drive
  43. my $disk_model = $smart->get_disk_model('/dev/sda');
  44. =head2 B<get_disk_temp(DEVICE)>
  45. Returns an array with the temperature of the device in Celsius and Farenheit, or N/A.
  46. C<DEVICE> - Device identifier of a single SSD / Hard Drive
  47. my ($temp_c, $temp_f) = $smart->get_disk_temp('/dev/sda');
  48. =head2 B<run_short_test(DEVICE)>
  49. Runs the SMART short self test and returns the result.
  50. C<DEVICE> - Device identifier of SSD/ Hard Drive
  51. $smart->run_short_test('/dev/sda');
  52. =head2 B<update_data(DEVICE)>
  53. Updates the SMART output and attributes for each device. Returns undef.
  54. C<DEVICE> - Device identifier of a single SSD / Hard Drive or a list of devices. If none are specified then get_disk_list() is called to detect devices.
  55. $smart->update_data('/dev/sda');
  56. =head1 COMPATIBILITY
  57. This module should run on any UNIX like OS with Perl 5.10+ and the smartctl progam installed from the smartmontools package.
  58. =head1 AUTHOR
  59. Paul Trost <ptrost@cpan.org>
  60. =head1 LICENSE AND COPYRIGHT
  61. Copyright 2015 by Paul Trost
  62. This script is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License v2, or at your option any later version.
  63. <http://gnu.org/licenses/gpl.html>