Edit: I made a small change to the daemon script to avoid an occasional blank temperature field. The line that sends the temperature to the temporary file is slow enough that it can get read by conky while it's being parsed and therefore empty. The new version avoids this.
Also, if you don't like the sleep command showing up in a ps command, install the "mksh" shell and change the first line of the daemon script from:
to:
The sleep command is a builtin for the mksh shell.
The smartctl command can get the temperature of an NVMe drive, but it takes twice as long as the nvme command. For this reason, I recommend installing nvme-cli and using the nvme command in the daemon shell script.
$ time sudo smartctl -a /dev/nvme0
...
real 0m0.100s
user 0m0.026s
$ time sudo nvme smart-log /dev/nvme0
...
real 0m0.046s
user 0m0.015s
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 or smartctl 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:
Find your nvme drive with ll:
Code:
$ ll /dev/nvme*
crw-------. 1 root root 239, 0 Jan 11 12:26 /dev/nvme0
brw-rw----. 1 root disk 259, 0 Jan 11 12:26 /dev/nvme0n1
brw-rw----. 1 root disk 259, 1 Jan 11 12:26 /dev/nvme0n1p1
...
The character device is all that's needed to get the temperature, so I used nvme0-temp as the daemon name. Change it as appropriate for your system.
Permissions and contents of /usr/local/bin/nvme0-temp:
Code:
$ ll /usr/local/bin/nvme0-temp
-rwxr-xr-x. 1 root root 245 Jan 11 12:13 /usr/local/bin/nvme0-temp
$ cat /usr/local/bin/nvme0-temp
#!/bin/bash
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 's/^[Tt]emperature *: *\([0-9]*\) C.*/\1/p')"
echo "$TEMPERATURE" > "$TEMPFILE"
sleep 2
done
Permissions and contents of /etc/systemd/system/nvme0-temp.service:
Code:
$ ll /etc/systemd/system/nvme0-temp.service
-rw-r--r--. 1 root root 137 Jan 11 11:26 /etc/systemd/system/nvme0-temp.service
$ cat /etc/systemd/system/nvme0-temp.service
[Unit]
Description=NVMe0 temperature monitor daemon
[Service]
ExecStart=/usr/local/bin/nvme0-temp
[Install]
WantedBy=multi-user.target
Once those two files are set up, just run:
Code:
$ sudo systemctl --now enable nvme0-temp
Created symlink /etc/systemd/system/multi-user.target.wants/nvme0-temp.service → /etc/systemd/system/nvme0-temp.service.
Then you can see the temperature with:
Code:
$ cat /tmp/nvme0-temp
33
You need something like this in your .conkyrc file to display the temperature:
Code:
${goto 825}${color0}NVMe: $color \
${if_existing /tmp/nvme0-temp}${tail /tmp/nvme0-temp 1 1}°C${endif}\
The tail command fails and conky aborts if the file doesn't exist, so the if_existing check keeps conky running with a blank temperature if the daemon stops for some reason.
The board chokes on the .conkyrc file that generates the banner in the screen shot, so here is the text part of it:
Code:
conky.text = [[
${goto 8}${color0}BAT:$color ${battery_short BAT1} ${battery_time BAT1}\
${goto 445}${color0}CPU:$color $cpu%\
${goto 555}${color0}CPU:$color ${hwmon 0 temp 1}°C\
${goto 675}${color0}Fan:$color ${hwmon 2 fan 1}rpm\
${goto 825}${color0}NVMe: $color \
${if_existing /tmp/nvme0-temp}${tail /tmp/nvme0-temp 1 1}°C${endif}\
${goto 965}${color0}SSD: $color ${hddtemp /dev/sda}°C\
${goto 1090}${color0}RAM:$color $memperc%\
${goto 1200}${color0}Down:$color ${downspeedf wlp3s0}KB/s\
${color0}Up:$color ${upspeedf wlp3s0}KB/s\
${alignr 2}${color0}${time %a}$color ${time %I:%M %p}
]]
dd_wizard