Tuesday, 22 September 2009

$image size vs. $image resizing, and a Simple Way to Make Conky Monitor Itself

Subbass recently made a comment on the Official Conky Blog that got me thinking: is it more efficient for Conky to resize an image in every iteration or for it to display an image "straight", without resizing it? Okay, seems like an obvious answer, but it raised the more interesting question: can you get Conky to display CPU and memory usage, but just for itself? It would be incredibly useful for us experimental types, to understand how we can make our Conkys more lightweight (given that the whole ethos of Conky to begin with is "a LIGHTWEIGHT system monitor").

With the help of dk75 and mobilediesel, I came up with the following, which uses ps to give the time-averaged CPU and memory usage of your Conky process(es):
${execpi 1 ps ux | grep -w conky | grep -v grep | awk '{print "CPU ",$3,"% MEM ",$4,"%"}'}

The important thing to note is that because it uses ps, the output is time-averaged over the entire life of the process. This is different to top, which shows the information since the last iteration of top. (Check the relevant man pages for more information.) Both programs have their uses; in the case of comparing the relative efficiency of different .conkyrcs, I find the ps method the most suitable. Incidentally, if you want to use top instead, you can use:
${execi 1 top -b -n1 -p $(pidof conky |awk '{gsub(" ", ",", $0); print}') |awk '/conky/ {print "CPU:",$9"%","MEM:",$10"%"}'}

The Test
I created three .conkyrc files, based on this one (my original config that was written for the Conky blog):
${image ~/images/bk_semi_trans_sq.png -p 3,5 -s 40x40}${image ~/images/bk_semi_trans_sq.png -p 47,5 -s 40x40}${image ~/images/bk_semi_trans_sq.png -p 91,5 -s 40x40}${image ~/images/bk_semi_trans_sq.png -p 135,5 -s 40x40}
${if_match ${desktop}==1}${image ~/images/wh_sq.png -p 3,5 -s 40x40}${endif}${if_match ${desktop}==2}${image ~/images/wh_sq.png -p 47,5 -s 40x40}${endif}${if_match ${desktop}==3}${image ~/images/wh_sq.png -p 91,5 -s 40x40}${endif}${if_match ${desktop}==4}${image ~/images/wh_sq.png -p 135,5 -s 40x40}${endif}
${execpi 1 ps ux | grep -w conky | grep -v grep | awk '{print "CPU ",$3,"% MEM ",$4,"%"}'}

Versions 2 and 3 were, respectively, using a set of 40x40px images and no resizing, and using a set of 10x10px images with resizing.

I ran each Conky for 10 minutes on its own, and at the end of the 10 minutes, took a screenshot capturing the CPU and memory percents.

Version 1, 50x50px images, scaled down to 40x40px, CPU 13.4% and MEM 1.0%:
From My Little Desktop Photos

Version 2, 40x40px images, no resizing, CPU 9.3% and MEM 1.0%:
From My Little Desktop Photos

Version 3, 10x10px images, scaled up to 40x40px, CPU 11.2% and MEM 1.0%:
From My Little Desktop Photos

In summary, it is most efficient to use the correctly-sized images for your Conky. However, if you must scale your images, best to use smaller images and scale up, rather than bigger ones scaled down.

I should note, that the CPU and memory percentages are obviously dependent on my system, which is just a little netbook, so forgive me if they seem prohibitively high! Also, you can improve the performance of this particular Conky greatly by increasing the update_interval; I was using 0.1s because I wanted my desktop indicator to switch quickly upon desktop change. However, if you're happy with a bit of a lag, you can always change it to 0.5s or 1s.

Monday, 21 September 2009

A cheap little battery widget :)

I liked my last battery widget, but it was a bit resource-hungry, what with all the images and that...So in a previous Conky config, I came up with a quick and easy way to get a battery-widget-like-thing, by using two battery bars, one of which was for a battery that doesn't exist (so it always shows empty).

I used:
${battery_bar 40,165 BAT1}${voffset 10}${battery_bar 20,10 BAT2}

to get this:
From My Little Desktop Photos

How to add a little Zen to your life, and why sed is my new favourite command

I've wanted to add quotes to my Conky for a while, and after coming across some discussions on Ubuntu Forums, I had a bit of a brain-child...There had to be a simple way (e.g. without an external script) to grab part of a website and parse it to display on my screen. I did a little research, and it turns out that a combination of curl and sed was what I needed. With a little help from my friends, I ended up with the following command (after TEXT in my Conky):
${alignr}${execpi 3600 curl --silent 'http://tinybuddha.com' | sed '{:q;N;s/\n/ /g;t q}'|grep -o '
[^<]*'|sed 's/
[[:blank:]]*//;s/[[:blank:]]*$//'|fold -sw 32 | sed -e 's/^/\${alignr}/' -e 's/ $//g'}

Basically, it uses curl to look at Tiny Buddha, an inspirational website featuring daily quotes. Then, for an explanation of all the sed commands, thanks to mobilediesel:
The first sed changes all newlines into spaces so the div tag will be on one line. Then grep looks for the div class="entry" up to the first < character. Then sed again to take out the div tag along with the spaces following it, then the spaces at the end. Then, obviously, through fold so it fits nicely on the desktop.

Since it's looking specifically for the div class="entry" tag, grep should find it even if the site layout changes.

The --silent suggestion is thanks to Crinos512.

Anyway, here's the result, a lovely minimal desktop, with just a battery bar (because I don't use any other indicators, not even a system tray these days!) and the time/date.
From Screenshots

Wednesday, 16 September 2009

It's a good day when...

...you make a top 15 list not once, but twice! Thanks jun auza :)

Saturday, 5 September 2009

...Mostly to show off :)

Well, there's not really anything innovative in my latest Conky; I was just trying to get something that was easily adaptable to all wallpapers. There are two versions:
From Screenshots

From Screenshots

...a light version and a dark version.

Both make use of the following: