egregius.be

Urban Exploration, PHP and others…

SSD smartctl usage

smartctl is a command line tool to read S.M.A.R.T. data from hard-drives and SSD’s.
I’ve been using it for several months now to monitor the writes on several SSD’s. Everyone knows by now that SSD’s have a limited lifetime. Each cell can only be written X times. X is mainly depending on the make and model of the SSD. Premium suppliers and Pro models have a higher rating than cheaper once. Also the size of the SSD is a big factor in this. Quite simple, the more cells there are the more you can write. How much data you can write is often specified at the product details page of the supplier. This amount is written in TBW with stands for TerraByte written. For example Samsung specifies for a 840 EVO 250GB 240 TBW, while a Samsung 860 PRO 256GB is specified at 300 TBW. The cheaper and smaller Kingston SA400S37 120GB only has 40 TBW and this is the drive that’s already at half of it’s lifetime. Reason enough for me to see if we could monitor that and take actions on it.
Below is some example code and scripts to read the S.M.A.R.T. data and store it in a MySQL database for further analyses. The table then shows all the details and calculates an expected EOL (End of Life) for the SSD.
Of course this is all theoretical, independent tests have already shown that a SSD might go way over these numbers.

The output of that page is for example:

This table can be live viewed at https://egregius.be/smart.php

What I’ve been doing to avoid writes and so extend the lifetime of the disks if for a future post. The table shows it was worth it, in 6 months the EOL expectancy of the Kingston drive is extended by one year.
Smartctl is installed by default on several Linux distributions and also in Mac OS. If it’s not installed you can simply install it with this command:

apt install smartmontools

Once installed you can view the S.M.A.R.T. details with a simple command:

/usr/local/bin/smartctl -A disk0

Output is depending on the disk, for example a Apple AP1024N SSD:

smartctl 7.1 2019-12-30 r5022 [Darwin 19.6.0 x86_64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF SMART DATA SECTION ===
SMART/Health Information (NVMe Log 0x02)
Critical Warning:                   0x00
Temperature:                        34 Celsius
Available Spare:                    100%
Available Spare Threshold:          99%
Percentage Used:                    0%
Data Units Read:                    3.545.332 [1,81 TB]
Data Units Written:                 3.615.435 [1,85 TB]
Host Read Commands:                 50.751.236
Host Write Commands:                44.701.359
Controller Busy Time:               0
Power Cycles:                       151
Power On Hours:                     18
Unsafe Shutdowns:                   19
Media and Data Integrity Errors:    0
Error Information Log Entries:      0

Because smartctl can also give the output in JSON it’s easy to be processed.

/usr/local/bin/smartctl -Aj disk0
{
  "json_format_version": [
    1,
    0
  ],
  "smartctl": {
    "version": [
      7,
      1
    ],
    "svn_revision": "5022",
    "platform_info": "Darwin 19.6.0 x86_64",
    "build_info": "(local build)",
    "argv": [
      "smartctl",
      "-Aj",
      "disk0"
    ],
    "exit_status": 0
  },
  "device": {
    "name": "disk0",
    "info_name": "disk0",
    "type": "nvme",
    "protocol": "NVMe"
  },
  "nvme_smart_health_information_log": {
    "critical_warning": 0,
    "temperature": 34,
    "available_spare": 100,
    "available_spare_threshold": 99,
    "percentage_used": 0,
    "data_units_read": 3545334,
    "data_units_written": 3615467,
    "host_reads": 50751432,
    "host_writes": 44702525,
    "controller_busy_time": 0,
    "power_cycles": 151,
    "power_on_hours": 18,
    "unsafe_shutdowns": 19,
    "media_errors": 0,
    "num_err_log_entries": 0
  },
  "temperature": {
    "current": 34
  },
  "power_cycle_count": 151,
  "power_on_time": {
    "hours": 18
  }
}

shell script to read the S.M.A.R.T. information and send it to a webserver.

The script can be automated on Debian etc in cron, or for example on Mac OS with a /Library/LaunchAgent

The script reads the data and sends it to receivesmart.php on a webserver. Inside receivesmart the json data is parsed and depending on the drive the necessary data is extracted and stored in the MySQL database.

Once the data is in the database it can be viewed in a table on a page.

Reacties zijn gesloten.