System monitoring with Conky

Conky is a lightweight system monitor that can display anything you can imagine on your desktop, and can run scripts to perform actions such as automatically shutting down the box under certain conditions.

Conky does not “just work” and requires (sometimes extensive) tweaking. It is a good fit for specific needs that cannot be met by more basic solutions. Almost infinitely configurable, there seems to be nothing it can’t do.

I have moved on to gkrellm, which meets my needs with far less work. But for what it’s worth, here’s what I learned about conky when I was test driving it. What follows assumes you have already set up hardware monitoring.

INSTALLATION AND SETUP
First, install conky. Many distributions have conky in their package manager.

Before you start the program, you need to have a .conkyrc file, which contains all the settings that control the behavior and appearance of Conky. Most conky packages install the default configuration file /etc/conky/conky.conf, so copy it to ~/.conkyrc. Then open ~/.conkyrc in a text editor and modify as desired.

You will probably find it easiest to modify your .conkyrc by seeing the results, so run conky: as user, conky. Make your desired changes to .conkyrc, kill and restart conky, and repeat as needed. Expect to spend a lot of time playing with it, first because you will need to and later because it is fun and you will have become addicted. You have been warned.

Once conky is to your liking, you may want to have it automatically start when you enter your graphical environment.

TIPS AND TRICKS
Conky uses pseudo-transparency, not true transparency: it reads the root window’s background and changes its own background to match. This fails in the case of window managers or desktop environments that set the background on a layer above the root window such as Xfce. There are multiple solutions to this; being lazy, I simply set my Xfce background to black.

Conky would seem to disappear when I clicked on the desktop. What was really happening was that conky would drop behind the Xfce background layer. On my system the problem is fixed by these changes per this discussion:

own_window yes
own_window_transparent no
own_window_type override

The details of hardware monitoring vary from motherboard to motherboard. The most practical thing to do is search the net for the specific chip(s) detected by lm_sensors. For example, I searched for “+conky cpu temp +w83627dhg-isa-0290” and quickly found this discussion which suggested I cat /sys/class/hwmon/hwmon0/device/* and see which files correspond to what parts of the output of sensors. Once the correct files were located, it was a simple job to add this line to my .conkyrc:

CPU: ${hwmon 0 temp 2}° Fan: ${hwmon 0 fan 2} rpm

Conky can execute commands. This line executes hddtemp -n /dev/sda every 60 seconds and displays the output:

${execi 60 hddtemp -n /dev/sda}°

Conky can perform conditional actions. This displays CPU temperature: using the default color if less than 70°, orange if between 70° and 73°, and red if greater than 73°:

${if_match ${hwmon 0 temp 2} > 73}
   ${color red}
   ${hwmon 0 temp 2}°
   ${color}
${endif}

${if_match ${hwmon 0 temp 2} <= 73}
   ${if_match ${hwmon 0 temp 2} >=70}
      ${color orange}
      ${hwmon 0 temp 2}°
      ${color}
   ${endif}
${endif}

${if_match ${hwmon 0 temp 2} < 70}
   ${hwmon 0 temp 2}°
${endif}

I’ve structured the code above for easy reading. Conky requires it on a single line and treats white space as significant, however, so the line in my .conkyrc rather cryptically reads:

${if_match ${hwmon 0 temp 2} > 73}${color red}${blink ${hwmon 0 temp 2}°}${color}${endif}${if_match ${hwmon 0 temp 2} <= 73}${if_match ${hwmon 0 temp 2} >=70}${color orange}${hwmon 0 temp 2}°${color}${endif}${endif}${if_match ${hwmon 0 temp 2} < 70}${hwmon 0 temp 2}°${endif}

I find it easier to write conky code in structured form, which I save in an accompanying file I name .conkyrc-README. Then I copy it to .conkyrc and strip the white spaces and returns. The .conkyrc-README file is retained as documentation. As examples, I have attached my .conkyrc and .conkyrc-README. Even doing this, however, writing conky code is a pain.

.conkyrc:

# .conkyrc
# Modified from the default /etc/conky/conky.conf by Warren Post, 22 May 2010
# See .conkyrc-README for documentation of TEXT section

alignment bottom_left
background no
border_width 1
color1 orange # Non-critical warning for investigation
color2 red # Critical warning requiring immediate shutdown
cpu_avg_samples 2
default_color lightgrey
default_outline_color red
default_shade_color green
double_buffer yes # Needed to eliminate flickering
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
use_xft yes
xftfont DejaVu Sans Mono:size=9
gap_x 5
gap_y 40 # Vertically aligns with Xfce bottom panel
# minimum_size 200 10 # Width, height in px
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
own_window yes # If no, desktop icons are lost
own_window_class Conky
own_window_transparent no # If yes, messes up desktop and CPU maxes out
own_window_type override # If normal or root, appears in non-root window; if desktop, Conky disappears when desktop is clicked on
stippled_borders 0
update_interval 1 # In seconds
uppercase no
use_spacer none
show_graph_scale no
show_graph_range no

TEXT
Temp: HD ${if_match ${execi 60 hddtemp -n /dev/sda} > 60}${color2}${execi 60 hddtemp -n /dev/sda}°${color}${endif}${if_match ${execi 60 hddtemp -n /dev/sda} <= 60}${if_match ${execi 60 hddtemp -n /dev/sda} >=45}${color1}${execi 60 hddtemp -n /dev/sda}°${color}${endif}${endif}${if_match ${execi 60 hddtemp -n /dev/sda} < 45}${execi 60 hddtemp -n /dev/sda}°${endif} CPU ${if_match ${hwmon 0 temp 2} > 73}${color2}${hwmon 0 temp 2}°${color}${endif}${if_match ${hwmon 0 temp 2} <= 73}${if_match ${hwmon 0 temp 2} >=70}${color1}${hwmon 0 temp 2}°${color}${endif}${endif}${if_match ${hwmon 0 temp 2} < 70}${hwmon 0 temp 2}°${endif}
CPU Fan ${hwmon 0 fan 2} rpm
CPU $cpu% ${cpubar 5}
RAM $memperc% ${membar 5}
Swap $swapperc% ${swapbar 5}
Network:
Up ${upspeed eth1} ${upspeedgraph eth1 8,50 lightgrey lightgrey 30}
Down ${downspeed eth1} ${downspeedgraph eth1 8,50 lightgrey lightgrey 30}

.conkyrc-README:

Documentation for .conkyrc
Warren Post, 23 May 2010

Since the TEXT section of .conkyrc neither allows structured code nor permits comments, this file documents it. Line numbers are counted from the "TEXT" line.

Line 1, first half: HD temp
---------------------------
Poll hddtemp every 60 seconds for hard disk temperature:

 ${execi 60 hddtemp -n /dev/sda}

Using above expression, display hard disk temperature. Use the default color if less than 45°, orange (color2) if between 45° and 60°, and red (color1) if greater than 60°:

 ${if_match ${execi 60 hddtemp -n /dev/sda} > 60}
 ${color2}
 ${execi 60 hddtemp -n /dev/sda}°
 ${color}
 ${endif}

 ${if_match ${execi 60 hddtemp -n /dev/sda} <= 60}
 ${if_match ${execi 60 hddtemp -n /dev/sda} >=45}
 ${color1}
 ${execi 60 hddtemp -n /dev/sda}°
 ${color}
 ${endif}
 ${endif}

 ${if_match ${execi 60 hddtemp -n /dev/sda} < 45}
 ${execi 60 hddtemp -n /dev/sda}°
 ${endif}

Line 1, second half: CPU temp
-----------------------------
CPU temperature is at /sys/class/hwmon/hwmon0/device/temp_2_input:

 ${hwmon 0 temp 2}

Display CPU temperature using conditional coloring as above. Use the default color if less than 70°, orange if between 70° and 73°, and red if greater than 73°.

Line 2: CPU fan
---------------
CPU fan velocity is at /sys/class/hwmon/hwmon0/device/fan_2_input:

 ${hwmon 0 fan 2}

Display CPU fan velocity using conditional coloring as above. Use the default color if fan is within 10% +/- of normal (1500 RPM) and orange if out of bounds. (Acceptable range 1350 - 1650 RPM) TODO in .conkyrc: Not yet implemented.

TODO in .conkyrc: Separate CPU bar by core. If swap usage is greater than 5%, color the bar orange. Force CPU, RAM, and swap usage numbers to display as two digits. Force network usage numbers to display in fixed units.

To have conky automatically hibernate the system if it overheats, see this discussion.

REFERENCES
Conky overview
Conky project site
Conky Hardcore
Conky Hardcore Support Forum

Advertisements

About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

7 Responses to System monitoring with Conky

  1. anonymous says:

    Anonym writes:Hi Warren, thank you for helpful examples. Now I know how to use the varialble/object hwmon. Works very good. Thank you very much.

  2. wpost says:

    Glad to be of help!

  3. anonymous says:

    Darek writes:thank you!http://webdarek.tumblr.com/

  4. webdarek says:

    Hello, I tried to use this code:${if_match ${hwmon 0 temp 2} >= 42}${color red}${blink ${hwmon 0 temp 2}°}${color}${endif}${if_match ${hwmon 0 temp 2} <= 73}${if_match ${hwmon 0 temp 2} >=70}${color orange}${hwmon 0 temp 2}°${color}${endif}${endif}${if_match ${hwmon 0 temp 2} < 70}${hwmon 0 temp 2}°${endif}and I receive blink but two numbers side by side….like this: http://postimage.org/image/95eig2179/there is probleme :cry: ?thank you ;)

  5. wpost says:

    I haven't revisited Conky since I wrote this article. Perhaps the support forum (see references, above) can help.

  6. Pingback: Hardware monitoring on Linux | A maze of twisty little passages

  7. Pingback: Setting up a lightweight workstation | A maze of twisty little passages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s