conky 1.8.1 vs conky 1.8.0 - regarding lua support.

I noticed a serious problem with the lua implementation in conky 1.8.1 (from the server-monitoring repo) compared to conky 1.8.0 (from the contrib repo). This doesn’t just affect openSUSE but conky 1.8.1 in general (same problem with this conky version under ArchLinux). Version 1.8.0 which I’m using under Ubuntu and under openSUSE again after downgrading works fine. Unfortunately I’m not sure that I will be able to downgrade conky everywhere. The picture left shows version 1.8.0 ; the picture right version 1.8.1 (same garbage under ArchLinux)

I could get the same result (as left) without using many of the lua functions I wrote to:

  • determine the number of CPUs
  • check the mounted filesystems
  • determine the name of the hardware sensors for CPU and mainboard temperature - however that wouldn’t be possible without lua unless you rewrite the conky configuration after each reboot because these names - like many things in modern Linuxes - are random >:(
  • determine the name of the default network interface (now p1p1 instead of eth0 under Fedora)
  • color CPU and filesystem usage using gradient and highlight top processes in a gradient of red (very useful)

Just a few examples to show how lua could make conky configuration much easier. In fact the .conkyrc file used in the example above could be used on other machines with totally different hardware without the need of changing anything.

The lua script is fine. if there were syntax errors, I would get plenty of warnings while starting conky on the command line. Even the crazy pipe* I opened in lua to find out the name of the sensors seems to work, as you can see the CPU and mainboard temperatures (right).

l = io.popen(“find -L /sys/class/hwmon/hwmon* -maxdepth 1 -regextype posix-awk -regex ‘.temp[0-9](label|crit|input)’ -exec echo -n ‘{}=’ ‘;’ -exec cat ‘{}’ ‘;’ | sed 's|/sys/class/hwmon/hwmon||;s|/temp||;s| ||g;s|| |;s|=|=|;s|$||’ | sort | awk ‘{ if ( P == $1 ) { print “#”, $NF } else print ; P=$1 }’ | sed -e :a -e ‘$!N;s/\
#/ /;ta’ -e ‘P;D’ | awk ‘{ if ( $4 ~ /label/ ) print $4, $1, $2, $3 ; else print “label=MB Temperature”, $1, $2, $3}’ | sed ‘s|label=||’ | awk ‘{ if ( $3 ~ /crit/ ) print $1, $2, $3 ; else print $1, $2, $3, “crit=10000” }’ | sed 's|
| |; s|crit=||;s|\(.
\) \(.\) \([0-9]\)\([0-9]\) \([0-9][0-9]\)|\1 = “${color0}\1 \2: ${color8}${if_match ${hwmon \3 temp \4}>=\5}${color red}${endif}${alignr}${hwmon \3 temp \4}C”|’”):lines()

I was planning to update conkyconf with the new version of the lua script (which is much better than the current one). But obviously I cannot do it now.

The problem starts when the variable lua_parse in conky returns a string containing several lines (separated by "
" ).
For example, I have a function conky_top (p,n) which returns the n top cpu or memory processes - the argument p being either ‘cpu’ or ‘mem’. (btw the output of memory usage on the picture I posted is wrong, but I fixed it in the meantime).
So the following variables in ~/.conkyrc work because they return only 1 line (as well as the cpu and mb temperature which work with 1.8.1):

${lua_parse top cpu 1}
${lua_parse top mem 1}

Here’s the conky_top function in the lua script (which I called /etc/conky/conky.lua):

-- display the n top processes
function conky_top (p,n)
	t = ""
	top = "top"
	if ( p == "mem" ) then top = "top_mem" end
	for i=1,tonumber(n) do
		usage = tonumber(conky_parse('${' .. top .. ' ' .. p .. ' ' .. i ..'}'))
		color = top_colour(usage, 0xd3, 25, 5)
		u = string.format("%s ${%s name %s}${alignr 80}${%s pid %s}${alignr 45}${%s cpu %s}${alignr 20}${%s mem %i}", color, top, i, top, i, top, i, top, i)
		if ( t == "" ) then t = u else t = t .. "
" .. u end
	return t

But the following variables garbage the entire conky output:

${lua_parse top cpu 2}
${lua_parse top mem 2}

Because these functions return 2 lines. Same thing for the filesystems. :frowning:

It’s not just with lua. Parsing of new lines is broken in conky 1.8.1. Many people reported similar issues while parsing the output of commands in conky.