Late to the party here, but I wanted to share a script I tweaked to monitor NVME TBW/GBW/health. Requires nvme-cli from Nerd Pack.
#!/bin/bash
#arrayStarted=true
# Ref:
# https://forums.unraid.net/bug-reports/stable-releases/683-docker-image-huge-amount-of-unnecessary-writes-on-cache-r733/page/16/?tab=comments#comment-9945
# SSDs
drives=(
"nvme0n1"
"nvme1n1"
)
for drive in ${drives[*]}
do
device=/dev/$drive
TBWSDB_TB=$(nvme smart-log $device | awk '/data_units_written/{ gsub(",", "") ; print $3 * 512000 / 1e+12 }')
TBWSDB_GB=$(nvme smart-log $device | awk '/data_units_written/{ gsub(",", "") ; print $3 * 512000 / 1e+9 }')
PWRON_DAYS=$(nvme smart-log $device | awk '/power_on_hours/{ print $3 / 24}')
HEALTH=$(nvme smart-log $device | awk '/percentage_used/{ print $3 }')
# Set permissions and clear previous average
touch /mnt/user/logs/"$drive"_health.log
chmod a+rw /mnt/user/logs/"$drive"_health.log
sed -i '/Average writes/d' /mnt/user/logs/"$drive"_health.log
echo "TBW on $(date +"%d-%m-%Y %H:%M:%S") --> $TBWSDB_TB TB, which is $TBWSDB_GB GB -- Health (% used, higher is worse): $HEALTH" >> /mnt/user/logs/"$drive"_health.log
echo "$TBWSDB_GB $PWRON_DAYS" | awk '{printf "Average writes/day: %.2fGB\n", $1/$2}' >> /mnt/user/logs/"$drive"_health.log
done