You are not logged in.

#1 2020-01-01 20:00:25

probackup-nl
Member
From: Delft
Registered: 2017-11-15
Posts: 43
Website

NVMe SSD total bytes written (TBW) daily logger using systemd timer

I wish to keep track of the the total bytes written to an Intel P600 NVMe (SSDPEKKW256G7) SSD.

I couldn't find anything anything ready made to copy and adapt. That is why I created some simple logger script that is daily once activated by a systemd timer. I stopped trying to insert the command in the ExecStart, after many hours I didn't think that the escaping effort was worth it, and moved the command to a shell file.

For the more novice Arch users, this is a step by step how to. Note, I prefer to use nano as editor.

# nano /usr/bin/log-tbw.sh
#!/bin/sh
/usr/bin/smartctl -A /dev/nvme0 | /bin/awk '$0~/Written/{ print strftime("%Y-%m-%d %H:%M:%S"), $3,$4,$5$6}' >> /var/log/nvme-tbw.log

Make the shell script executable:

# chmod +x /usr/bin/log-tbw.sh

Create the systemd required service file:

# nano /etc/systemd/system/log-tbw.service
[Unit]
Description=Log NVMe TBW value

[Service]
Type=oneshot
ExecStart=/usr/bin/log-tbw.sh

Create the timer, so the service will be called once every day at 4 o'clock:

# nano /etc/systemd/system/log-tbw.timer
[Unit]
Description=Log NVMe TBW value daily
Requires=log-tbw.service

[Timer]
OnCalendar=*-*-* 4:00:00
Persistent=true

[Install]
WantedBy=timers.target

Now test the created files and start the daily job:

# systemd-analyze verify /etc/systemd/system/log-tbw.service
# systemd-analyze verify /etc/systemd/system/log-tbw.timer
# systemctl enable log-tbw.timer && systemctl start log-tbw.timer

That will output something like this after a few days:

# cat /var/log/nvme-tbw.log
2019-12-28 04:00:12 Written: 309,002,362 [158TB]
2019-12-29 04:00:14 Written: 309,002,366 [158TB]
2019-12-30 04:00:15 Written: 309,002,379 [158TB]
2019-12-31 04:00:13 Written: 309,002,388 [158TB]
2020-01-01 04:00:14 Written: 309,003,114 [158TB]

These bytes were written during a "Power on time" of 117 days 1 year with a package reduced Arch, that logs in memory, and has one application server installed. Linearly extrapolated next SSD purchese requires at least 2466 790 TBW for 5 years warranty (nearest price effective match -> Micron 7300 MAX M.2 400GB -> 2,2 PBW PNY XLR8 CS3030 500GB -> 800 TBW). Note that all nearly all data is written twice because of BTRFS Data, Metadata and System duplication:

# btrfs fi usage /
...
Data,DUP: Size:13.82GiB, Used:4.24GiB
   /dev/nvme0n1p2	  27.63GiB

Metadata,DUP: Size:512.00MiB, Used:55.80MiB
   /dev/nvme0n1p2	   1.00GiB

System,DUP: Size:32.00MiB, Used:16.00KiB
   /dev/nvme0n1p2	  64.00MiB

Last edited by probackup-nl (2020-01-02 19:09:11)

Offline

#2 2020-01-02 13:57:57

Nickolas0
Member
Registered: 2019-02-16
Posts: 24

Re: NVMe SSD total bytes written (TBW) daily logger using systemd timer

Your stats are quite impressive as for just 117 days. I have below 7TB written for 3 years on heavy use desktop system.

Offline

#3 2020-01-02 14:35:35

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,901
Website

Re: NVMe SSD total bytes written (TBW) daily logger using systemd timer

Nickolas0 wrote:

Your stats are quite impressive as for just 117 days. I have below 7TB written for 3 years on heavy use desktop system.

Agreed... I'm around 2.7 TB written with 15k power on hours.  I do have a spinner for some storage though...


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2020-01-02 18:21:34

probackup-nl
Member
From: Delft
Registered: 2017-11-15
Posts: 43
Website

Re: NVMe SSD total bytes written (TBW) daily logger using systemd timer

I am still trying to figure out the amount that has been written since last boot:

# uptime
 19:09:49 up 73 days,  4:04,  1 user,  load average: 0.00, 0.04, 0.01
[asrock1 ~]# cat /sys/block/nvme0n1/queue/hw_sector_size
512
[asrock1 ~]# cat /proc/diskstats | grep nvme
 259       0 nvme0n1 80500 25721 5949027 38693 6825949705 0 308736768496 1089225331 0 2011989168 2297992728 0 0 0 0

I think that the 7th column (308736768496) is the number of sectors written.

Thus I think that 143.7 TBW (1 kilobyte = 1024 bytes, x 1024 = megabyte, x 1024 = gigabyte, x 1024 = terabyte) has been written to it during the last 73 days.

Please correct me where I am wrong...

Note: the machine is running a webserver at a non-standard port, and a java based application to receive backup data from 2 computers. Backup data itself is written to spinners [106GBW @/proc/diskstats].

Last edited by probackup-nl (2020-01-02 22:34:50)

Offline

Board footer

Powered by FluxBB