I have this Conky report on my desktop screen:

enter image description here

This is a relevant part of the conky.conf file:

${color1}${font ConkySymbols:size=16}J${font} ${voffset -10}Memory» $hr${color}
${color1}${goto 35}RAM : ${color}$mem/$memmax ${alignr}$memperc% ${membar 4,100}
${color1}${goto 35}SWAP: ${color}$swap/$swapmax $alignr}$swapperc% ${swapbar 4,100}

However when I run free -m I get this:

enter image description here

Which is 2GB less than the Conky's report (6GB vs 8.3GB).

I also tried running the mem command in terminal, but the command is not recognized.

How to run in the terminal the command that Conky uses to find used/free RAM stats and why is there a difference with the free -m command?


${color1}${goto 35}RAM: ${execi 10 free --si -m|awk '/^Mem/{printf "%.2f",$3/1024}'}/$memmax ${execi 10 free --si -m|awk '/^Mem/{printf "%.1f%%", 100*$3/$2}'} \
${execibar 10 free --si -m|awk '/^Mem/{print 100*$3/$2}'}

enter image description here

  • 2
    I might be off base here but it looks as though Conky is adding the used and shared together. – Terrance Jan 20 at 18:16

From the sources it seems that info.mem is calculated as info.memmax - memavail where these are read from /proc/meminfo in fields:

    if (strncmp(buf, "MemTotal:", 9) == 0) {
      sscanf(buf, "%*s %llu", &info.memmax);
    } else if (strncmp(buf, "MemAvailable:", 13) 
      sscanf(buf, "%*s %llu", &memavail);

To call free from conky you can use, for example,

RAM: ${execi 10 free --si -m|awk '/^Mem/{printf "%.2fGiB\n",$3/1024}'}/$memmax   \
${execi 10 free --si -m|awk '/^Mem/{printf "%.1f%%\n", 100*$3/$2}'} \
${execibar 10 free --si -m|awk '/^Mem/{print 100*$3/$2}'}

but the size of the bar generated by execibar is fixed by global variables you have to set in the conky.config part with:

default_bar_height = 4,
default_bar_width = 100,

The output of free is is passed to awk which looks for the line beginning Mem and takes the 3rd ($3) word on the line and reformats it (see man sprintf). You can set the number of decimal places in the format %.2f by changing the number 2.

  • Is there some other $ command that I can use inside conky.conf for it to display correct memory usage? – parsecer Jan 20 at 19:22
  • 1
    The definition of "correct" is ambiguous. Conky gives a useful value that also includes memory used to implement tmpfs filesystems (such as /tmp). If you want to, you can use the output of free -m. I'll add an example to my answer. – meuh Jan 20 at 19:42
  • Could you please show how I need to change the conky RAM line? I tried to use your code, but it didn't work correctly (see last edit on the question) – parsecer Jan 21 at 16:21
  • I found the error (extra $). I replaced 10 with 2- it's the renewal rate, right? How would I get it to display 2 decimal points though? eg 3.42 instead of 3.4? And what is the |awk '/^Mem/{print $3}' part responsible for? – parsecer Jan 21 at 16:28
  • And I'm not sure how to update the ram percentage bar – parsecer Jan 21 at 16:33

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.