0

I would like to install Ubuntu on SSD (I know that i Have to set TRIM, noatime, etc..) But I would like to know if I can check how many GB was written in last day / week / month.

Because I would like to measure how many GB is written every day on SSD if folders /var and /tmp were on SSD. If there would be less than 10GB writes per day I think it is cool and it will not damage SSD much.

And no I don't want to use ramdisk :)

  • To some extent it is possible, but you need to run a dedicated program for that. The info about read/writes to drives can be found under /proc directory (forget which file it is exactly ), but that info will only show you total reads and writes since boot time. If you want I can write a script or gui indicator that will do the job – Sergiy Kolodyazhnyy Mar 5 '17 at 0:31
  • Are you a programmer? :) Because on Windows there are apps like SSDLife which shows data written today, yesterday, last 7 days and total, so I think it must be possible to get these data from SSD :) – tomsk Mar 5 '17 at 11:50
  • Well, I consider myself so far an amateur programmer, although my major in college is slightly different. I'll look into that Windows apps at some point. If that's open source that's even better - i might be able to figure out how exactly it works – Sergiy Kolodyazhnyy Mar 5 '17 at 19:54
  • Are you a developer of omgubuntu.co.uk/2016/10/… ? Nice :) I programm in C++ (Qt) and Perl, I would like to create something like Open Hardware Monitor but only for linux :) – tomsk Mar 5 '17 at 20:08
  • Yep, that's me :) I work mostly in shell, Python, and currently learning more and more Perl. Let me know if you ever would like to collaborate on a project ;) – Sergiy Kolodyazhnyy Mar 5 '17 at 20:11
1

As it often happens, I jumped ahead to reinvent the wheel that already exists in smartmontools package. This package provides whole lot of diagnostic tools for hard-drives and SSDs (or in more technical terms, SCSI devices). In particular, smartctl command is what we're looking for:

$ sudo smartctl -A /dev/sda
[sudo] password for xieerqi: 
smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.4.0-65-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 18
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  5 Runtime_Bad_Block       0x0000   000   000   000    Old_age   Offline      -       0
  9 Power_On_Hours          0x0000   100   100   000    Old_age   Offline      -       8080
 12 Power_Cycle_Count       0x0000   100   100   000    Old_age   Offline      -       1419
171 Avail_OP_Block_Count    0x0000   100   100   000    Old_age   Offline      -       40907856
174 Pwr_Cycle_Ct_Unplanned  0x0000   100   100   000    Old_age   Offline      -       78
195 Total_Prog_Failures     0x0000   100   100   000    Old_age   Offline      -       0
196 Total_Erase_Failures    0x0000   100   100   000    Old_age   Offline      -       0
197 Total_Unc_Read_Failures 0x0000   100   100   000    Old_age   Offline      -       0
208 Average_Erase_Count     0x0000   100   100   000    Old_age   Offline      -       179
210 SATA_CRC_Error_Count    0x0000   100   100   000    Old_age   Offline      -       0
224 In_Warranty             0x0000   100   100   000    Old_age   Offline      -       1
233 Remaining_Lifetime_Perc 0x0000   095   095   000    Old_age   Offline      -       95
241 Host_Writes_GiB         0x0000   100   100   000    Old_age   Offline      -       3133
242 Host_Reads_GiB          0x0000   100   100   000    Old_age   Offline      -       2745
249 Total_NAND_Prog_Ct_GiB  0x0000   100   100   000    Old_age   Offline      -       301548705

What you see above is list of attributes for my SSD. Of particular interest is attribute 241 (Host_Writes_GiB) and 242 (Host_Reads_GiB). These values are in GiB (which is a classical unit of measure in computer science in powers of 1024 bytes, in this case 1024^3, instead of SI units of powers of 10).

On the low level, as far as I understand, this utility parses actual lifetime_write_kbytes file in /sys/fs folder. Particularly, in my example:

$ cat /sys/fs/ext4/sda1/lifetime_write_kbytes              
4793857835

Of course, this is a command-line utility. If you don't have it installed (check via apt-cache policy smartmontools) then install it via sudo apt-get install smartmontools. There is Gnome Disks Utility as GUI alternative and it comes with Ubuntu.

There are couple caveats however:

  • SMART information has to be provided by the device. If the device is fairly cheap and doesn't have such information, then it would require reinventing the wheel just like I originally wanted to do via monitoring /proc/diskstats file.
  • The specific attributes must be provided by the device. For instance, information on tnfd22 ssd found on smartmontools website doesn't provide such information.

There's also a bit of a problem: the resulting information shown is total history of reads/writes. Thus, you cannot extract reads/writes within last x number of days. At least it's not possible with smartctl or none of the tools I found thus far. However, what you can do, is schedule a daily cron task that will read /sys/fs/ext4/sda1/lifetime_write_kbytes and append the data with time stamp to a file. Later on, you can subtract differences to see how much was written in each day. For instance, contents of such command would be:

30 08 * * * bash -c '{ date; cat /sys/fs/ext4/sda1/lifetime_write_kbytes; echo ;} >> /home/user/my_disk_log.txt'
  • Thanks, so it will runs every day at 08:30? And what happens when at that time computer wont be turned on? – tomsk Mar 5 '17 at 19:35
  • @tomsk yep, that's at 8:30 AM each day. Obviously if computer isn't running at the time, it won't be executed. What else you could do is use @reboot keyword to run command whenever your computer starts up. Look into cron options, there's other things that you can do with it. Here's for instance, this : thegeekstuff.com/2009/06/15-practical-crontab-examples – Sergiy Kolodyazhnyy Mar 5 '17 at 19:52
  • But I don't want to run script each time PC boots up, only once per day.. and if the script will be in /etc/cron.daily ? How does it work if computer is not running? :) – tomsk Mar 5 '17 at 20:03
  • @tomsk /etc/cron.daily works kind of the same - it runs each day at 6:25 (set in /etc/crontab). – Sergiy Kolodyazhnyy Mar 5 '17 at 20:07
  • So it means that TRIM doesn't work at all.. hmm interesting.. maybe only solution is to create script which runs at startup and checks if that script was executed that day, if no, then script will be executed :D – tomsk Mar 5 '17 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.