EDIT: With kernel 5.5, none of this is necessary. You can simply use hwmon
. Example:
${hwmon nvme temp 1}
Taken from Is there an hddtemp fork that reads NVMe drives?
Conky can execute a shell command from within the .conkyrc file, but the developers recommend against it for efficiency reasons. Also, since you must run
nvme
orsmartctl
as root, you get sudo spam in the logs. So this post describes a very short shell script and systemd unit file that put the temperature in a file in/tmp
that is world readable for conky to use. If the daemon dies for some reason, the file in/tmp
is deleted. Otherwise, the last known temperature would be returned and you'd have no idea it was a fictitious reading.
Instructions:
Install mksh
and nvme-cli
or smartmontools
. Either can be used, examples below.
sudo pacman -Syu mksh nvme-cli
or
sudo pacman -Syu mksh smartmontools
Find your nvme drive, usually nvme0
:
$ ls -l /dev/nvme*
crw------- 1 root root 244, 0 Oct 30 07:47 /dev/nvme0
brw-rw---- 1 root disk 259, 0 Oct 30 07:47 /dev/nvme0n1
brw-rw---- 1 root disk 259, 1 Oct 30 07:47 /dev/nvme0n1p1
brw-rw---- 1 root disk 259, 2 Oct 30 07:47 /dev/nvme0n1p2
Create the daemon script and open it in your favorite text editor like nano
, gedit
or kate
:
touch ~/.local/bin/nvme0-temp
nano ~/.local/bin/nvme0-temp
Paste the contents (for nvme-cli
):
#!/usr/bin/mksh
tempfile="/tmp/nvme0-temp"
trap "rm -f "$tempfile"; exit" 0 1 2 3 13 15 # Exit, HUP, INT, QUIT, PIPE, TERM
while true; do
temperature="$(nvme smart-log /dev/nvme0 | sed -n '/^[Tt]emperature *: *\([0-9]*\).*/{s//\1/p;q}')"
builtin echo "$temperature" > "$tempfile"
builtin sleep 2
done
Paste the contents (for smartmontools
):
Thanks to @anon27588196
#!/usr/bin/mksh
tempfile="/tmp/nvme0-temp"
trap "rm -f "$tempfile"; exit" 0 1 2 3 13 15 # Exit, HUP, INT, QUIT, PIPE, TERM
while true; do
temperature="$(smartctl -A /dev/nvme0 | grep Temperature: |awk '{printf "%.0f",($2)}')"
builtin echo "$temperature" > "$tempfile"
builtin sleep 2
done
Now make it executable:
chmod +x ~/.local/bin/nvme0-temp
Now create the service file and open in a text editor:
sudo touch /usr/lib/systemd/system/nvme0-temp.service
sudo nano /usr/lib/systemd/system/nvme0-temp.service
Paste the contents:
[Unit]
Description=NVMe temperature monitor daemon
[Service]
ExecStart=~/.local/bin/nvme0-temp
[Install]
WantedBy=multi-user.target
Start and enable the service:
systemctl enable --now nvme0-temp
You can see the temperature with:
$ cat /tmp/nvme0-temp
40
Add this to your .conkyrc file:
${if_existing /tmp/nvme0-temp}${tail /tmp/nvme0-temp 1 1}°C${endif}
If you prefer Fahrenheit:
${if_existing /tmp/nvme0-temp}${execi 60 echo $(($(cat /tmp/nvme0-temp) * 9 / 5 + 32))}°F${endif}
My wonky conky: