Sunday, August 1, 2010

Conky

Introducing Conky

conky desktop image

Conky is a free tool for embedding information into your X desktop. I use it during the work day to keep an eye on my computer's resources and to help remind me how I should be utilizing my own resources.

This tutorial isn't designed to teach you how to use Conky. For that, you'll have to check out the Conky documentation. However, this tutorial will show you how to customize Conky to embed information in your Ubuntu desktop, just like the image to the right.

Configuring Conky

Conky is configurable through the .conkyrc file in your home directory. In order to get Conky to produce the output shown above, I made a few changes to the standard sample .conkyrc file, which you can find at /usr/share/doc/conky/examples/conkyrc.sample.gz.

Conky's colors are highly configurable. I've selected a nice earthy palette of yellow, orange and gray.

# Colors
default_color BDB76B # Values
color0 FF8C00 # Headers
color1 lightgrey # Line Items
color2 BDB76B # Highlighted Values

Next I use my newly defined color palette to draw attention to the processes that are currently consuming the most cpu and memory resources on my computer.

${color1} ${top name 1} ${top pid 1} ${color2}${top cpu 1}${color1} ${top mem 1}
...

${color1} ${top_mem name 1} ${top_mem pid 1} ${top_mem cpu 1} ${color2}${top_mem mem 1}

I've also asked Conky to embed the contents of a text file into my desktop. Specifically, I like to always see my TODO list.

${color0}TODO:${color1}
${execi 30 cat /home/username/Desktop/TODO.txt | fold -w40 }

Integrating all of the tweaks described above, I arrived at the .conkyrc configuration file cataloged below.

################################ Conky Settings ################################

# set to yes if you want Conky to be forked in the background
background no

# X font when Xft is disabled, you can pick one with program xfontsel
font arial

# Use Xft?
use_xft yes

# Xft font when Xft is enabled
xftfont Bitstream Vera Sans Mono:size=11

# Text alpha when using Xft
xftalpha 0.8

# mail spool
mail_spool $MAIL

# Update interval in seconds
update_interval 5.0

# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0

# Create own window instead of using desktop (required in nautilus)
own_window yes

# If own_window is yes, you may use type normal, desktop or override
own_window_type override

# Use pseudo transparency with own_window?
own_window_transparent yes

# If own_window_transparent is set to no, you can set the background colour here
own_window_colour hotpink

# If own_window is yes, these window manager hints may be used
own_window_hints undecorated,below,sticky

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Minimum size of text area
minimum_size 280 5

# Draw shades?
draw_shades no

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no

# Draw borders around graphs
draw_graph_borders yes

# Stippled borders?
stippled_borders 8

# border margins
border_margin 4

# border width
border_width 1

# Default border colors
default_shade_color black
default_outline_color black

# Text alignment, other possible values are commented
alignment top_right

# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 20
gap_y 50

# Subtract file system buffers from used memory?
no_buffers yes

# set to yes if you want all text to be in uppercase
uppercase no

# number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 2

# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 2

# Force UTF8? note that UTF8 support required XFT
override_utf8_locale no

# Add spaces to keep things from moving about? This only affects certain objects.
use_spacer no

# Colors
default_color BDB76B # Values
color0 FF8C00 # Headers
color1 lightgrey # Line Items
color2 BDB76B # Highlighted Values

################################ Screen Text ################################

TEXT
$nodename - $sysname $kernel on $machine
$hr
${color0}Summary:$color
${color1}IP:$color ${addr eth0} ${alignr}${color1}Uptime:$color $uptime_short

${color1}CPU Usage:$color $cpu% ${cpubar}
${color1}RAM Usage:$color $mem/$memmax - $memperc% ${membar}
${color1}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar}
$color$hr

${color0}File Systems:$color
/ $color${fs_used /}/${fs_size /} ${fs_bar /}
$color$hr
${color} Name             PID     CPU%   MEM%
${color0}Top CPU:$color
${color1} ${top name 1} ${top pid 1} ${color2}${top cpu 1}${color1} ${top mem 1}

${color1} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${color1} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${color1} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
${color0}Top Mem:$color

${color1} ${top_mem name 1} ${top_mem pid 1} ${top_mem cpu 1} ${color2}${top_mem mem 1}
${color1} ${top_mem name 2} ${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2}
${color1} ${top_mem name 3} ${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3}
${color1} ${top_mem name 4} ${top_mem pid 4} ${top_mem cpu 4} ${top_mem mem 4}

$hr
${color0}Network Connections:$color ${tcp_portmon 1 65535 count}
$color Inbound Ports: ${tcp_portmon 1 32767 count}  Outbound Ports: ${tcp_portmon 32768 61000 count}
${color0}Outbound Connection ${alignr} Remote Service/Port${color1}
${tcp_portmon 32768 61000 rhost 0} ${alignr} ${tcp_portmon 32768 61000 rservice 0}
${tcp_portmon 32768 61000 rhost 1} ${alignr} ${tcp_portmon 32768 61000 rservice 1}
${tcp_portmon 32768 61000 rhost 2} ${alignr} ${tcp_portmon 32768 61000 rservice 2}
${tcp_portmon 32768 61000 rhost 3} ${alignr} ${tcp_portmon 32768 61000 rservice 3}
${tcp_portmon 32768 61000 rhost 4} ${alignr} ${tcp_portmon 32768 61000 rservice 4}

${color0}Inbound Connection ${alignr} Local Service/Port${color1}
${tcp_portmon 1 32767 rhost 0} ${alignr} ${tcp_portmon 1 32767 lservice 0}
${tcp_portmon 1 32767 rhost 1} ${alignr} ${tcp_portmon 1 32767 lservice 1}
${tcp_portmon 1 32767 rhost 2} ${alignr} ${tcp_portmon 1 32767 lservice 2}
${tcp_portmon 1 32767 rhost 3} ${alignr} ${tcp_portmon 1 32767 lservice 3}
${tcp_portmon 1 32767 rhost 4} ${alignr} ${tcp_portmon 1 32767 lservice 4}

$hr
${color0}TODO:${color1}
${execi 30 cat /home/username/Desktop/TODO.txt | fold -w40 }

Running Conky at Login

In order to enjoy the Conky configuration features described in the section above, you may also want to know how to run Conky automatically when you log in. To do so, you need to configure a new startup program for your Ubuntu session, which you can do by clicking System -> Preferences -> Sessions.

Sometimes Conky acts finicky if you start it up before your X session has had time to stabilized, so I have my Conky startup program call this shell script.

#!/bin/sh
sleep 30 && conky

No comments:

Post a Comment