1

I am using conky 1.10.3 (conky-all) in Ubuntu 16.10 (x86-64), kernel 4.8.0-59-generic, Cinnamon 3.0.7.

How can I create a bar for diskio (actually, one for diskio_read and another for diskio_write)?
Conky has diskio (which gives a number) and diskiograph - no bars.

I tried, but could not find a way, to use something like ${execbar $diskio}.

I also messed a little with a lua script, namely BARGRAPH WIDGET v2.1 by wlourf, http://u-scripts.blogspot.com/2010/07/bargraph-widget.html but, although using

{
    name="cpu",
    --arg="%S",
    max=100,
    angle=90,
    alarm=50,
    bg_colour={0x00ff00,0.25},
    fg_colour={0x00ff00,1},
    alarm_colour={0xff0000,1},
    x=0,y=610,
    blocks=1,
    height=250,width=25,
    smooth=true,
    mid_colour={{0.5,0xffff00,1}}

}

works, if I put "diskio" instead of "cpu" I get an empty bar (while conky's diskiograph clearly shows disk IO).

1

The main problem when using name="diskio_read" and diskio_write with the given lua bargraph widget is that these two functions return numbers like 2.33KiB rather than simple integers like 12345. The widget only uses the lua function tonumber() to convert returned values, and this fails on these strings.

The other problem is that of course you need to set max= to some suitable value (eg 100000000) as the disk io is not scaled to 100% like the cpu.

You can get round the first problem, if you are not using any other conky features, by resetting the global variable that requests values to be human readable:

conky.config = {
  format_human_readable = false,
  ...

Alternatively, you can edit the widget file, bargraph.lua, in function setup_bar_graph(), change the line:

value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))

to something like

local result = conky_parse(string.format('${%s %s}', t.name, t.arg))
value = tonumber(result)
if value==nil then value = my_tonumber(result) end

and add your own tonumber function just before the function conky_main_bars().

-- https://unix.stackexchange.com/a/409006/119298
function my_tonumber(n)
  local capture = {string.match(n,"^(%d+\.?%d*)([KMGTPB])")}
  if #capture<=0 then return 0 end
  local v = tonumber(capture[1])
  if #capture==1 then return v end
  if capture[2]=="K" then return v*1024 end
  if capture[2]=="M" then return v*1024*1024 end
  if capture[2]=="G" then return v*1024*1024*1024 end
  if capture[2]=="T" then return v*1024*1024*1024*1024 end
  return v
end
  • Hello and thanks a lot for your response. \n I figured there should be a problem with $diskio values like "20,13KiB", so I tried to use ${exec echo $eval{$diskio} | sed -e 's/[a-zA-Z ]*$//' -e 'y/,/./'} but it outputs nothing in conky. The same with ${exec ${eval $cpu}} - which gives "#sh: 1: Bad substitution" in the terminal. \n I'll test your advice and let you know - thanks again. \n PS\n I also tried things like $${...}, but it just outputs e.g. "$diskio". Is there anything more concise than plain "man conky"? – GregStef Dec 5 '17 at 20:31
  • You might get some more examples in the wiki. You can also look at an answer to another question on conky that uses eval and $$. – meuh Dec 5 '17 at 21:34
  • Can't comment on your eval post, but: ${exec netup} gives "eno1", ${downspeed eno1} gives "212B", ${downspeed ${exec netup}} gives "0B", ${downspeed $${exec netup}} gives "0B", ${downspeed ${exec echo ${exec netup}}} gives "0B", ${eval $${downspeed ${exec netup}}} gives "${downspeed eno1}", ${exec ${eval $${downspeed ${exec netup}}}} gives(in terminal) "sh: 1: Bad substitution", ${exec $${eval ${downspeed ${exec netup}}}} gives(in terminal) "sh: 1: Bad substitution", ${exec ${eval $${downspeed ${exec netup}}}}gives(in terminal) "sh: 1: Bad substitution" – GregStef Dec 6 '17 at 12:13
  • Maybe I'm being thick, but I cannot seem to grasp the syntax - I also cannot put a newline in the comment (Firefox/Ubuntu)! – GregStef Dec 6 '17 at 12:15
  • Yes, this seems to be a bug introduced by 1.10, which was a major rewrite. It works as intended in 1.9.1. The github sources are fixed (currently version 1.10.7, but 1.10.4 may be ok too). For example, this should display the time in the window: ${eval "Local time is $${time %a, %d %b %Y %T %z}"} – meuh Dec 6 '17 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.