[Solution]Is there an hddtemp fork that reads NVMe drives?
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2009
    Posts
    2,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Solution]Is there an hddtemp fork that reads NVMe drives?

    The title says it all. I've checked copr, poked around in github, and googled with no luck. The nvme command can grab the temperature, but doing shell commands in a conky script uses a lot of resources.

    dd_wizard

    EDIT - Solution is in post #8. Thread moved to guides and solutions. Thanks dd_wizard!

  2. #2
    Join Date
    Jun 2005
    Location
    Montreal, Que, Canada
    Posts
    6,425
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Is there an hddtemp fork that reads NVMe drives?

    Would the drives be registered with SMART?

    Try smartctl -a your_drive. Generally, these drives run so cool that the drive will only note the temp of the surroundings.

    Example follows:
    Code:
    sudo  smartctl -a /dev/nvme0
    smartctl 6.6 2016-05-31 r4324 [x86_64-linux-5.0.0-25-generic] (local build)
    Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF INFORMATION SECTION ===
    Model Number:                       Sabrent
    Serial Number:                      CD8E07951E9E52181935
    Firmware Version:                   ECFM12.2
    PCI Vendor/Subsystem ID:            0x1987
    IEEE OUI Identifier:                0x6479a7
    Total NVM Capacity:                 1,024,209,543,168 [1.02 TB]
    Unallocated NVM Capacity:           0
    Controller ID:                      1
    Number of Namespaces:               1
    Namespace 1 Size/Capacity:          1,024,209,543,168 [1.02 TB]
    Namespace 1 Formatted LBA Size:     512
    Local Time is:                      Mon Sep  2 08:59:36 2019 EDT
    Firmware Updates (0x12):            1 Slot, no Reset required
    Optional Admin Commands (0x0007):   Security Format Frmw_DL
    Optional NVM Commands (0x0054):     DS_Mngmt Sav/Sel_Feat *Other*
    Maximum Data Transfer Size:         512 Pages
    Warning  Comp. Temp. Threshold:     70 Celsius
    Critical Comp. Temp. Threshold:     90 Celsius
    
    Supported Power States
    St Op     Max   Active     Idle   RL RT WL WT  Ent_Lat  Ex_Lat
     0 +    10.73W       -        -    0  0  0  0        0       0
     1 +     7.69W       -        -    1  1  1  1        0       0
     2 +     6.18W       -        -    2  2  2  2        0       0
     3 -   0.0490W       -        -    3  3  3  3     2000    2000
     4 -   0.0018W       -        -    4  4  4  4    25000   25000
    
    Supported LBA Sizes (NSID 0x1)
    Id Fmt  Data  Metadt  Rel_Perf
     0 +     512       0         2
     1 -    4096       0         1
    
    === START OF SMART DATA SECTION ===
    SMART overall-health self-assessment test result: PASSED
    
    SMART/Health Information (NVMe Log 0x02, NSID 0xffffffff)
    Critical Warning:                   0x00
    Temperature:                        32 Celsius
    Available Spare:                    100%
    Available Spare Threshold:          5%
    Percentage Used:                    0%
    Data Units Read:                    1,624,717 [831 GB]
    Data Units Written:                 832,804 [426 GB]
    Host Read Commands:                 16,581,947
    Host Write Commands:                2,975,542
    Controller Busy Time:               34
    Power Cycles:                       61
    Power On Hours:                     344
    Unsafe Shutdowns:                   8
    Media and Data Integrity Errors:    0
    Error Information Log Entries:      1,617
    Warning  Comp. Temperature Time:    0
    Critical Comp. Temperature Time:    0
    
    Error Information (NVMe Log 0x01, max 63 entries)
    Num   ErrCount  SQId   CmdId  Status  PELoc          LBA  NSID    VS
      0       1617     8  0x00f5  0x400c      -   2147483648     1     -
      1       1616     8  0x00f5  0x400c      -   2147483648     1     -
      2       1615     8  0x00f5  0x400c      -   2147483648     1     -
      3       1614     8  0x00f5  0x400c      -   2147483648     1     -
      4       1613     8  0x00f5  0x400c      -   2147483648     1     -
      5       1612     8  0x00f5  0x400c      -   2147483648     1     -
      6       1611     2  0x0098  0x400c      -   2147483648     1     -
      7       1610     2  0x0098  0x400c      -   2147483648     1     -
      8       1609     2  0x0098  0x400c      -   2147483648     1     -
      9       1608     2  0x0098  0x400c      -   2147483648     1     -
     10       1607     2  0x0098  0x400c      -   2147483648     1     -
     11       1606     2  0x0098  0x400c      -   2147483648     1     -
     12       1605     4  0x00ae  0x400c      -   2147483648     1     -
     13       1604     4  0x00ae  0x400c      -   2147483648     1     -
     14       1603     4  0x00ae  0x400c      -   2147483648     1     -
     15       1602     4  0x00ae  0x400c      -   2147483648     1     -
    ... (47 entries not shown)
    Last edited by lsatenstein; 2nd September 2019 at 02:02 PM. Reason: Provided nvme example
    Leslie in Montreal

    Interesting web sites list
    http://forums.fedoraforum.org/showth...40#post1697840

  3. #3
    Join Date
    Dec 2013
    Location
    United Kingdom
    Posts
    7,155
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Re: Is there an hddtemp fork that reads NVMe drives?

    Quote Originally Posted by lsatenstein
    Would the drives be registered with SMART?

    Try smartctl -a your_drive. Generally, these drives run so cool that the drive will only note the temp of the surroundings.
    actually like high performance RAM modules, nvme drives get hot in use, if not cooled properly they will throttle back to reduce temperature. that's why some motherboards come with nvme heat spreaders and it's useful to know the current temperature of them initially when you build a system and put it through it's paces to know that the nvme has sufficient airflow to keep optimal performance.

  4. #4
    Join Date
    Sep 2009
    Posts
    2,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Is there an hddtemp fork that reads NVMe drives?

    Sadly, hddtemp hasn't been updated in years. However, the udisks project is working on temperature reporting for NVMe drives in the future. In the mean time, I wrote a systemd daemon that puts the NVMe temperature in a file in /tmp for access by conky. Trying to read it directly with conky spams the logs with sudo requests and has a detectable performance hit.

    dd_wizard

  5. #5
    Join Date
    Dec 2013
    Location
    United Kingdom
    Posts
    7,155
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Re: Is there an hddtemp fork that reads NVMe drives?

    sounds very handy, please could you write up how to do this?

  6. #6
    Join Date
    Sep 2009
    Posts
    2,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Is there an hddtemp fork that reads NVMe drives?

    Should I put it in guides or this thread?

    dd_wizard

  7. #7
    Join Date
    Dec 2013
    Location
    United Kingdom
    Posts
    7,155
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Re: Is there an hddtemp fork that reads NVMe drives?

    i can make this into a guide thread if you want to add the information here

  8. #8
    Join Date
    Sep 2009
    Posts
    2,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Is there an hddtemp fork that reads NVMe drives?

    Edit 1: I made a small change to the daemon script to avoid an occasional blank temperature field. The temporary file was truncated before getting and parsing the temperature. The new version avoids this by splitting up parsing and writing to the file.

    Edit 2: After doing some profiling, I changed the recommendation to use mksh to default. I added the profiling results as a new post.

    The smartctl command can get the temperature of an NVMe drive, but it is much slower than the nvme commad. Also, the best shell for this script is mksh.

    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:

    Install mksh and nvme-cli with your favorite package manager.

    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
    
    #!/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="$(/usr/sbin/nvme smart-log /dev/nvme0 | /usr/bin/sed -n '/^[Tt]emperature *: *\([0-9]*\).*/{s//\1/p;q}')"
        builtin echo "$temperature" > "$tempfile"
        builtin 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
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screenshot at 2019-01-11 16-27-49.jpg 
Views:	145 
Size:	206.0 KB 
ID:	29980  
    Last edited by dd_wizard; 19th February 2019 at 08:24 PM. Reason: Small change to avoid occaisonal blank temperature displays.

  9. #9
    Join Date
    Sep 2009
    Posts
    2,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [Solution]Is there an hddtemp fork that reads NVMe drives?

    The top output was generated with the S command active. This includes the time spent executing child processes such as the nvme and sed commands as well as the daemon script itself.
    Code:
     PID USER  PR  NI   VIRT   RES   SHR S %CPU %MEM    TIME+ COMMAND                                  
    2154 root  20   0   2596  1664  1468 S  0.0  0.0  0:02.41 /usr/bin/mksh /usr/local/bin/nvme0-temp
    2184 root  20   0   8968  4140  3596 S  0.0  0.0  0:02.63 /usr/bin/ksh /usr/local/bin/nvme0-tempy
    2192 root  20   0  17256  4132  3756 S  0.0  0.0  0:02.91 /usr/bin/zsh /usr/local/bin/nvme0-tempz
    2174 root  20   0  14928  3552  3212 S  0.0  0.0  0:03.59 /usr/bin/bash /usr/local/bin/nvme0-tempx
    2166 root  20   0   2596  1664  1472 S  0.0  0.0  0:09.61 /usr/bin/mksh /usr/local/bin/nvme0-tempa
    The smallest memory footprint and lowest execution time are given by mksh. The shells tested all have some form of builtin sleep, except for bash, which was included as a base line.

    The only difference between nvme0-temp and nvme0-tempa was the use of "smartctl -A /dev/nvme0" by nvme0-tempa. All the other daemons used "nvme smart-log /dev/nvme0" to read the drive temperature. You can see that smartctl is much slower than nvme.

    The profiling was carried out for approximately 15 minutes, which yields 0.27% total time spent in the daemon script and the child processes.

    The ".sh" extension was added to each file so the board would upload it. The scripts were tested without the extension.

    dd_wizard
    Attached Files Attached Files
    Last edited by dd_wizard; 13th March 2019 at 06:02 PM.

  10. #10
    Join Date
    Jun 2004
    Location
    Maryland, US
    Posts
    7,744
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Re: [Solution]Is there an hddtemp fork that reads NVMe drives?

    Might be nice to make a named pipe and read,write the temp value to that instead of wearing your SSD

  11. #11
    Join Date
    Sep 2009
    Posts
    2,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [Solution]Is there an hddtemp fork that reads NVMe drives?

    Almost every installation will have /tmp in RAM, so I didn't bother with a named pipe. But I'll look into that.

    dd_wizard

Similar Threads

  1. Issue installing F29 Silverblue on mix of NVME & physical drives?
    By joncr in forum Installation, Upgrades and Live Media
    Replies: 2
    Last Post: 6th December 2018, 01:17 PM
  2. Replies: 0
    Last Post: 8th July 2018, 10:42 PM
  3. iostat svctm and %busy numbers are wrong for NVME drives
    By bobx001 in forum Servers & Networking
    Replies: 2
    Last Post: 25th June 2018, 05:57 PM
  4. hddtemp
    By lsatenstein in forum Fedora Focus
    Replies: 0
    Last Post: 7th March 2018, 01:11 AM
  5. hddtemp
    By ferd in forum Using Fedora
    Replies: 21
    Last Post: 1st November 2005, 09:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •