How to use conky and lm sensors (CPU temperature)
October 15, 2011 6 Comments
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:
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 noTEXT
$sysname $kernel on $machineUptime $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}Cwlan0 $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%
$membarRoot $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).

that does NOT work at all!!!!!!!!!!!!!
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.
it does works.. just it’s linux.. cut and paste not always works.. need to add some “customize” according to your own computer..
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…
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.
I have been busy lately, but now I have posted my full conkyrc