How to use conky and lm sensors (CPU temperature)

If you don’t know what conky it, be sure to check it out. Anyway, I have for a long time been using conky to monitor some critical temperatures on my computer, ever since I had a problem with my graphic cards overheating severly after building my computer. 

What I found was a string using sensors and then cut away some of the unwanted information. My problem was that it included the degrees symbol from the command. So, I had to learn how to use cut. Now, I started with the basic command just getting the temperature:

sensors | grep ‘Core 0’

Since I use a multi core CPU, I fetch the temperature of each core separately. The above will show something like this:

Core 0: +37.0°C (high = +80.0°C, crit = +98.0°C)

As seen, there is allot of unwanted information displayed there. So we just cut out the part we want using cut:

sensors | grep ‘Core 0’ | cut -c17-21

Which will only display the +37,0 (or you can change it to cut -c18-21 so it won’t show the +). It might be different on other computer, but the basic principle is the same. If you want to experiment a bit with it, I would suggest you start out with using cut -c1-30, which lets you keep character (or column) 1 to 30, then you just change until you have desired result. Also note that for my system cut -c17-22 and cut -c17-21 showed the same result in the terminal, but the first showed some messed up characters in conky.

Anyway, now that you have a command that lets you fetch out your CPU temp, you can easily translate it to conky. Here is what I used, for my quad core CPU:

Core 01: $alignr ${execi 30 sensors | grep ‘Core 0’ | cut -c18-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C
Core 02: $alignr ${execi 30 sensors | grep ‘Core 1’ | cut -c18-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C
Core 03: $alignr ${execi 30 sensors | grep ‘Core 2’ | cut -c18-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C
Core 04: $alignr ${execi 30 sensors | grep ‘Core 3’ | cut -c18-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C

Note the last part, which is there only to get it to show °C instead ^ÅC or something similar, which is also why I cut out the degree symbol from the command. And finally, a full screenshot of my conky setup:

My conky set up

 

background yes
use_xft yes
xftfont HandelGotD:size=9
xftalpha 0.5
update_interval 4.0
total_run_times 0
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 200 5
maximum_width 220
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_color grey
default_shade_color red
default_outline_color green
alignment top_right
gap_x 12
gap_y 48
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale no

TEXT
$sysname $kernel on $machine

Uptime $alignr $uptime
Load $alignr $loadavg
Core 01: $alignr ${execi 30 sensors | grep “Core 0” | cut -c17-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C
Core 02: $alignr ${execi 30 sensors | grep “Core 1” | cut -c17-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C
Core 03: $alignr ${execi 30 sensors | grep “Core 2” | cut -c17-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C
Core 04: $alignr ${execi 30 sensors | grep “Core 3” | cut -c17-21}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C
GPU: $alignr ${execi 60 nvidia-settings -query GPUCoreTemp | perl -ne ‘print $1 if /GPUCoreTemp.*?: (\d+)./;’}${iconv_start UTF-8 ISO_8859-1}° ${iconv_stop}C

wlan0 $alignr ${addr wlan0}

Inbound $alignr ${downspeed wlan0} kb/s
${downspeedgraph wlan0}
Outbound $alignr ${upspeed wlan0} kb/s
${upspeedgraph wlan0}

$processes processes ($running_processes running)

CPU $alignr ${cpu cpu0}%
${cpubar cpu0}

MEM $alignc $mem / $memmax $alignr $memperc%
$membar

Root $alignc ${fs_used /} / ${fs_size /} $alignr ${fs_free_perc /}%
${fs_bar /}

Home $alignc ${fs_used /home} / ${fs_size /home} $alignr ${fs_free_perc /home}%
${fs_bar /home}

Videos $alignc ${fs_used /home/me/Videos} / ${fs_size /home/me/Videos} $alignr ${fs_free_perc /home/me/Videos}%
${fs_bar /home/me/Videos}

swap $alignc $swap / $swapmax $alignr $swapperc%
${swapbar}

NAME $alignr PID CPU
${top name 1} $alignr ${top pid 1} ${top cpu 1}
${top name 2} $alignr ${top pid 2} ${top cpu 2}
${top name 3} $alignr ${top pid 3} ${top cpu 3}
${top name 4} $alignr ${top pid 4} ${top cpu 4}
${top name 5} $alignr ${top pid 5} ${top cpu 5}

As promised, though a bit late, my full .conkyrc. Please note, blindly copying this might not work, you will have to edit for your own system, e.g. my GPU temp is fetched via nvidia-settings, so if you have a ATi card, this will of course not work. Also the speed graphs need the correct device (for me it is wlan0, for you it could be eth0 or wlan1 or whatever).

14 Responses to How to use conky and lm sensors (CPU temperature)

  1. scott says:

    that does NOT work at all!!!!!!!!!!!!!

    • MagnusB says:

      It does work, but you might have to do some changes. As I said, I empirically tested this to get the best result, starting with cut -c1-40 or something like that, making sure I got everything, then I changed each number (1 higher and 40 lower) until I had what I wanted.

      First make sure lm sensors work, run sensors, and if that does not yield any result, run

      sudo sensors-detect

      Let the script do it things, then re run sensors. As I said, the above code is for a quad core processor, so if you have a dual core, or single core, the output of sensors are different.

      • Guru Biters says:

        it does works.. just it’s linux.. cut and paste not always works.. need to add some “customize” according to your own computer..

  2. joris says:

    nice thanks, does work well on ubuntu 11.10. Only thing I had to change was “Core 0″ into ‘Core 0’

    Care to post you’re total conkyrc? It looks better than mine… 😉

    • MagnusB says:

      Thanks, I did not notice that error 🙂 Post corrected.

      I can post my entire conkyrc. I think I based it off an existing one somewhere, then did some minor changes to it, and made it fit my screen…. Will get it on it when I get home later.

    • MagnusB says:

      I have been busy lately, but now I have posted my full conkyrc 🙂

  3. whit says:

    my core temp is not being displayed, i have a quad core as you do what am i doing wrong?

    • MagnusB says:

      Run
      sensors | grep 'Core 0'
      If the output of that is correct, you need to cut at the right places. If it isn’t, you need to config sensors by running
      sudo sensors-detect
      And follow the instructions.

  4. Hi, great guide! i have used it for my conky. it is possible to use only one “execi” for extract many lines?

    • MagnusB says:

      Probably, but it will probably require a more complicated .conkyrc. I haven’t used this in two years, but glad people still find it useful 😀

  5. thefatdemon says:

    This may be pretty old but thank you. I was having trouble getting just the temperature for conky.
    I’m using the LSD2 conky widget from ConkyManager and was having trouble getting a number to even show. Thanks 😀

    • MagnusB says:

      As you said, this is fairly old and I haven’t used conky in quite some time. I also have no idea what LSD2 is or how that works. If you used my guide above, check that you have lmsensors installed, they are configured and are working.I really dont have a Linux box running anymore, hence why I really don’t update this blog anymore.

  6. Michael says:

    Hello, and thank you very much for this really great guide! It ended my endless trying how to get cpu core temperature on my desktop without ever and ever typing “sensors” in a console-window.
    You could add a little hint for other users: the output of sensors will not be identical on every next machine; it can be freely configured in the file /etc/sensors3.conf (or in a similar config-file for sensors, according to the linux-distribution you are using; so you can there determine yourself, what and how it is shown in the output and what you have to grep for the use in conky. (This config may even change with an update of the sensors package in your distri, so you’ll have to rewrite the line in conkyrc after this happens.)

    • MagnusB says:

      Holy ****, this post is ancient, and I had no idea this blog was even relevant anymore. Unfortunately, I dont run a Linux PC anymore and best I can do is a virtual machine (and in my mind this is cheating), as I gave away the last desktop running Linux that a year or so ago for reasons (and I miss it sorely). Honestly saying, if this post is at all relevant, I can change it, though I need guidance to what exactly you feel need changing. At the time I wrote this, running conky needed a bit more insight (meaning you never tried it unless you were dedicated) and I totally understand the times have changed and we deserve better.

      If anyone else feel they can do better, feel free to be inspired by the post above, a link would be nice but not necessary, as IIRC, I based my work on another guide I found severely missing at the time and experimented to make it work.

      By the way, Manjaro rules….

Leave a comment