Conky is a lightweight system monitoring tool. It has many built-in probes (processor load, memory usage, temperature sensors, etc), but it is still pretty easy to extend it if you don’t find the feature you need.

In this post I’ll describe my Conky setup and explain how to extend it to monitor your rTorrent downloads.

rTorrent is a great BitTorrent client which offers an XML-RPC interface to its core functions, making it easy to get the downloads status through scripting. You can read more about that in this previous post.

Starting by the end

Here is a screenshot of the final Conky layout we’re going to setup throughout this post.

There are actually 2 instances of Conky running simultaneously : one for the calendar widget on the left, and one for the system monitor containing the rTorrent status on the right.

conky-full-thumb

The calendar widget

I can’t take credit for this calendar widget, which I’ve found in the forums. It took juste a little bit of tweaking to get to this Conky configuration file :

?Download .conkyrc_cal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
own_window yes
own_window_type desktop
own_window_transparent yes
own_window_hints undecorated,below,skip_taskbar,skip_pager,sticky
 
update_interval 5
 
minimum_size 250
alignment ml
double_buffer yes
 
use_xft yes
xftfont DejaVu Sans Mono:size=20
#xftfont Bitstream Vera Sans:size=8
 
TEXT
$alignc${time %H:%M}
${color red}$hr$color
${time %A} ${time %d} ${time %B}
${color red}$hr$color
${execpi 300 cal | sed -e 's/'`date | awk '{print $3}'`'/\$\{color e84448}'`date | awk '{print $3}'`'\$\{color}/'}

execpi is the directive responsible for creating the calendar. It basically executes a shell one-liner which output is then used as a Conky configuration snippet. It runs at 300 seconds (5 minutes) intervals not to waste computing resources.

This is the end result :

conky-calendar

The system monitor

The system monitor requires a basic Conky configuration file and a perl script.

Conky configuration file for the system monitor

The system monitor Conky configuration file is a simple one, with standard Conky elements. The only “original part” is the one collecting rTorrent information : like for the calendar widget, an execpi directive is used to run the “rtorrent-status.pl” every minute (60 seconds).

?Download .conkyrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
own_window yes
own_window_type desktop
own_window_transparent yes
own_window_hints undecorated,below,skip_taskbar,skip_pager,sticky
 
update_interval 5
text_buffer_size 512
 
minimum_size 250
alignment mr
double_buffer yes
 
use_xft yes
#xftfont Fixed:size=12
xftfont Bitstream Vera Sans:size=8
 
TEXT
${color red}CPU$color       ${hwmon 0 fan 2} RPM
Core0  ${cpubar cpu1 4,200} @ ${freq 1} MHz ${hwmon 1 temp 1}C
Core1  ${cpubar cpu2 4,200} @ ${freq 2} MHz ${hwmon 2 temp 1}C
Core2  ${cpubar cpu3 4,200} @ ${freq 3} MHz ${hwmon 3 temp 1}C
Core3  ${cpubar cpu4 4,200} @ ${freq 4} MHz ${hwmon 4 temp 1}C
 
${color red}MEMORY$color
Memory ${goto 60} ${membar 4,200} ${memperc}%
Swap   ${goto 60} ${swapbar 4,200} ${swapperc}%
 
${color red}HDD$color
sda    ${diskio sda} ${alignc 50}${hddtemp /dev/sda}
 
${color red}NET$color
Down   ${downspeedf eth0} KiB/s
Up     ${upspeedf eth0} KiB/s
 
${color red}BitTorrent$color
${execpi 60 ~/bin/rtorrent-status.pl}

Perl Script to collect rTorrent download information

The following script pulls the information from the remote rTorrent client and outputs it as Conky configuration elements which are used by Conky through the execpi directive.

This script requires the Frontier::Client perl module, which I automatically got when I installed the xmlrpc-c package (I use gentoo and I had to set the “tools” USE flag for this package. If you use a different Linux distro, you might have to sort out this point).

It also require that rTorrent be installed/configured with XML-RPC enabled, and that the XML-RPC interface be exported through a HTTP server. It seems like a lot of work, but it is not if you follow those instructions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/perl
 
use strict;
use warnings;
 
use Frontier::Client;
use Data::Dumper;
 
# Configuration
 
use constant server		=> 'http://spaghetti/RPC2';
use constant bt_stats	=> '/tmp/rtorrent_data';
 
# Do not edit below this comment
 
my $server = Frontier::Client->new(url => server);
my $result = $server->call('d.multicall', "main", 
	"d.get_base_filename=",
	"d.get_bytes_done=",
	"d.get_size_bytes=",
	"to_kb=\$d.get_down_rate=");
 
open DATA, ">" . bt_stats;
 
my $idx = 1;
my @res;
foreach my $d (@$result) {
	my $cur = $d->[1];
	my $max = $d->[2];
	my $dl_rate = $d->[3];
	print DATA $cur/$max, "\n";
	push @res,
		sprintf("%.40s \${alignr}%7.1f KiB/s\$alignr\n" . 
			" " x 5 . "%3.2f%%" . "\${goto 70}\${execbar sed -ne '$idx p' " .
			bt_stats . '}', $d->[0], $dl_rate, 100 * $cur / $max);
	$idx++;
}
close DATA;
 
print join("\n\n", @res), "\n";

Here is the end result for this :

conky-main

Bringing it all together

Finally I wrote this shell script to start both Conky instances at once. You can add this script in the “autorun” or equivalent settings for your desktop environment.

?Download conky.sh
1
2
3
4
#! /bin/sh
 
conky -dc ~/.conkyrc
conky -dc ~/.conkyrc_cal

That’s all folks !

That was it. If you didn’t know how flexible and easy to extend Conky truly is, I hope this post will have helped you to get started writing your own Conky widgets and monitoring/extension scripts.

If you have any question or suggestion, please share them in the comments.

October 11, 2009 at 3:02 pm by Stephane Kattoor
Category: Software