Linux:software:conky

From Linux How-To Repository

Jump to: navigation, search

Contents

The Excellent Conky

With Conky you can display machine stats on your desktop in various ways. Simply install it via the Synaptic Package Manager.

Links

Conky Homepage: http://conky.sourceforge.net/

Ubuntu Forums: http://ubuntuforums.org/showthread.php?t=205865

Howtoforge: http://howtoforge.com/conky_system_monitor_on_ubuntu704

Load at Startup

Go to System > Preferences > Sessions > Startup Programs and add 'Conky' to the list. Conky will be active after your next reboot!

Compiz may draw unwanted shadows around your display, in which case start Conky with a script. Just create a script in your home directory:

   gedit .conky_start.sh 

Make sure it is executable:

   chmod a+x .conky_start.sh

Inside the script file put this:

   #!/bin/bash
   sleep 10 && conky;

This will start conky after 60 seconds from your login. Actually, 10 seconds works for me.

Go to System > Preferences > Sessions > Startup Programs and edit the Conky startup command so that it contains the path to the script.

Basic Configuring

First make a configuration file in your home directory:

   gedit /home/username/.conkyrc

Now all you do is paste the configuration code in it. Some example code is found here:

   /usr/share/doc/conky/examples/conkyrc.sample.gz

However, you can get better ready-made code elsewhere, such as those submitted by users on forums or the Conky Homepage.

Paste the settings into the file and save. The configuration settings are pretty easy to follow. Just look at the TEXT part to figure it out. Once you change something, open a terminal and run this to reload and test your changes:

   killall -SIGUSR1 conky

Here is an example from the Ubuntu forums (from a user called Pengo):

# UBUNTU-CONKY
# A comprehensive conky script, configured for use on
# Ubuntu / Debian Gnome, without the need for any external scripts.
#
# Based on conky-jc and the default .conkyrc.
# INCLUDES:
# - tail of /var/log/messages 
# - netstat connections to your computer
#
# -- Pengo (conky@pengo.us)
#

# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# fiddle with window
use_spacer yes
use_xft no

# Update interval in seconds
update_interval 3.0

# Minimum size of text area
# minimum_size 250 5

# Draw shades?
draw_shades no

# Text stuff
draw_outline no # amplifies text if yes
draw_borders no
font arial
uppercase no # set to yes if you want all text to be in uppercase

# Stippled borders?
stippled_borders 3

# border margins
border_margin 9

# border width
border_width 10

# Default colors and also border colors, grey90 == #e5e5e5
default_color grey

own_window_colour brown
own_window_transparent yes

# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
gap_x 10
gap_y 10

# stuff after 'TEXT' will be formatted on screen

TEXT
$color
${color orange}SYSTEM ${hr 2}$color
$nodename $sysname $kernel on $machine

${color orange}CPU ${hr 2}$color
${freq}MHz   Load: ${loadavg}   Temp: ${acpitemp}
$cpubar
${cpugraph 000000 ffffff}
NAME             PID       CPU%      MEM%
${top name 1} ${top pid 1}   ${top cpu 1}    ${top mem 1}
${top name 2} ${top pid 2}   ${top cpu 2}    ${top mem 2}
${top name 3} ${top pid 3}   ${top cpu 3}    ${top mem 3}
${top name 4} ${top pid 4}   ${top cpu 4}    ${top mem 4}

${color orange}MEMORY / DISK ${hr 2}$color
RAM:   $memperc%   ${membar 6}$color
Swap:  $swapperc%   ${swapbar 6}$color

Root:  ${fs_free_perc /}%   ${fs_bar 6 /}$color 
hda1:  ${fs_free_perc /media/hda1}%   ${fs_bar 6 /media/hda1}$color
hdb3:  ${fs_free_perc /media/hdb3}%   ${fs_bar 6 /media/hdb3}

${color orange}NETWORK (${addr eth0}) ${hr 2}$color
Down: $color${downspeed eth0} k/s ${alignr}Up: ${upspeed eth0} k/s
${downspeedgraph eth0 25,140 000000 ff0000} ${alignr}${upspeedgraph eth0 
25,140 000000 00ff00}$color
Total: ${totaldown eth0} ${alignr}Total: ${totalup eth0}
Inbound: ${tcp_portmon 1 32767 count} Outbound: ${tcp_portmon 32768 
61000 count}${alignr}Total: ${tcp_portmon 1 65535 count}

${color orange}LOGGING ${hr 2}$color
${execi 30 tail -n3 /var/log/messages | fold -w50}

${color orange}FORTUNE ${hr 2}$color
${execi 120 fortune -s | fold -w50}

If the network connections graph does not work, change all "eth0" references to appropriate devices, i.e. "ppp0" (for modem) or "ath0" (for some other devices).

For testing, simply run the conky script you made from a terminal window:

   sh .conky_start.sh

Other Variables

  Variable         Arguments                  Description                
  acpiacadapter                     ACPI ac adapter state.                   
  acpifan                           ACPI fan state                           
  acpitemp                          ACPI temperature.                        
  adt746xcpu                        CPU temperature from therm_adt746x       
  adt746xfan                        Fan speed from therm_adt746x             
  battery           (num)           Remaining capasity in ACPI or APM        
                                    battery. ACPI battery number can be      
                                    given as argument (default is BAT0).     
  buffers                           Amount of memory buffered                
  cached                            Amount of memory cached                  
  color             (color)         Change drawing color to color            
  cpu                               CPU usage in percents                    
  cpubar            (height)        Bar that shows CPU usage, height is      
                                    bar's height in pixels                   
  downspeed         net             Download speed in kilobytes              
  downspeedf        net             Download speed in kilobytes with one     
                                    decimal                                  
  exec              shell command   Executes a shell command and displays    
                                    the output in torsmo. warning: this      
                                    takes a lot more resources than other    
                                    variables. I'd recommend coding wanted   
                                    behaviour in C and posting a patch :-).  
  execi             interval, shell Same as exec but with specific interval. 
                    command         Interval can't be less than              
                                    update_interval in configuration.        
  fs_bar            (height), (fs)  Bar that shows how much space is used on 
                                    a file system. height is the height in   
                                    pixels. fs is any file on that file      
                                    system.                                  
  fs_free           (fs)            Free space on a file system available    
                                    for users.                               
  fs_free_perc      (fs)            Free percentage of space on a file       
                                    system available for users.              
  fs_size           (fs)            File system size                         
  fs_used           (fs)            File system used space                   
  hr                (height)        Horizontal line, height is the height in 
                                    pixels                                   
  i2c               (dev), type, n  I2C sensor from sysfs (Linux 2.6). dev   
                                    may be omitted if you have only one I2C  
                                    device. type is either in (or vol)       
                                    meaning voltage, fan meaning fan or temp 
                                    meaning temperature. n is number of the  
                                    sensor. See /sys/bus/i2c/devices/ on     
                                    your local computer.                     
  kernel                            Kernel version                           
  loadavg           (1), (2), (3)   System load average, 1 is for past 1     
                                    minute, 2 for past 5 minutes and 3 for   
                                    past 15 minutes.                         
  machine                           Machine, i686 for example                
  mails                             Mail count in mail spool. You can use    
                                    program like fetchmail to get mails from 
                                    some server using your favourite         
                                    protocol. See also new_mails.            
  mem                               Amount of memory in use                  
  membar            (height)        Bar that shows amount of memory in use   
  memmax                            Total amount of memory                   
  memperc                           Percentage of memory in use              
  new_mails                         Unread mail count in mail spool.         
  nodename                          Hostname                                 
  outlinecolor      (color)         Change outline color                     
  pre_exec          shell command   Executes a shell command one time before 
                                    torsmo displays anything and puts output 
                                    as text.                                 
  processes                         Total processes (sleeping and running)   
  running_processes                 Running processes (not sleeping),        
                                    requires Linux 2.6                       
  shadecolor        (color)         Change shading color                     
  stippled_hr       (space),        Stippled (dashed) horizontal line        
                    (height)        
  swapbar           (height)        Bar that shows amount of swap in use     
  swap                              Amount of swap in use                    
  swapmax                           Total amount of swap                     
  swapperc                          Percentage of swap in use                
  sysname                           System name, Linux for example           
  time              (format)        Local time, see man strftime to get more 
                                    information about format                 
  totaldown         net             Total download, overflows at 4 GB on     
                                    Linux with 32-bit arch and there doesn't 
                                    seem to be a way to know how many times  
                                    it has already done that before torsmo   
                                    has started.                             
  totalup           net             Total upload, this one too, may overflow 
  updates                           Number of updates (for debugging)        
  upspeed           net             Upload speed in kilobytes                
  upspeedf          net             Upload speed in kilobytes with one       
                                    decimal                                  
  uptime                            Uptime                                   
  uptime_short                      Uptime in a shorter format               

  seti_prog                         Seti@home current progress
  seti_progbar      (height)        Seti@home current progress bar
  seti_credit                       Seti@hoome total user credit

Font Examples:

${font Dungeon:style=Bold:pixelsize=10}I can change the font as well
${font Verdana:size=10}as many times as I choose
${font Perry:size=10}Including UTF-8,
${font Grunge:size=12}${time %a  %b  %d}${alignr -25}${time %k:%M}

Add In Temperature

Source: http://news.softpedia.com/news/How-to-Install-lm-sensors-on-Ubuntu-47205.shtml

To install open Synaptic or type:

   sudo apt-get install lm_sensors

Then create a device making script. It is only run once and can be saved to any location:

   sudo gedit mkdev.sh

Paste in this code:

#!/bin/bash

# Here you can set several defaults.

# The number of devices to create (max: 256)
NUMBER=32

# The owner and group of the devices
OUSER=root
OGROUP=root
# The mode of the devices
MODE=600

# This script doesn't need to be run if devfs is used
if [ -r /proc/mounts ] ; then
if grep -q "/dev devfs" /proc/mounts ; then
echo "You do not need to run this script as your system uses devfs."
exit;
fi
fi

i=0;

while [ $i -lt $NUMBER ] ; do
echo /dev/i2c-$i
mknod -m $MODE /dev/i2c-$i c 89 $i || exit
chown "$OUSER:$OGROUP" /dev/i2c-$i || exit
i=$[$i + 1] 
done
#end of file

Make the file executable:

   chmod +x mkdev.sh

Then run it:

   sudo ./mkdev.sh

Finally, run the sensors detection program. Install it if it isn't installed:

   sudo sensors-detect

Answer YES to all questions, including to automatically put entries in /etc/modules.

Open a terminal and type

   sudo gedit /etc/modules

You will see a list similar to this:

# Generated by sensors-detect on Thu Feb 15 12:15:11 2007
# I2C adapter drivers
# modprobe unknown adapter NVIDIA i2c adapter 2 at 2:00.0
i2c-isa
# I2C chip drivers
eeprom
it87

Load each module listed there. Replace the modules in the example with the ones found on your system.

sudo modprobe i2c-isa
sudo modprobe eeprom
sudo modprobe it87

Run the following command to get the data from sensors.

   sensors

If everything is working, you should see something like this:

Output . . .
Output . . .

Optionally, you can install a front-end that shows the sensor info in Gnome or KDE.

For Gnome (Add applet to taskbar):

   sudo apt-get install sensors-applet

For KDE:

   sudo apt-get install ksensors

Troubleshooting

Flickering

Add dbe module to /etc/X11/xorg.conf to reduce flickering.

   sudo gedit /etc/X11/xorg.conf

Find the section titled Section "Module" and add this:

   Load    "dbe"

Kbuntu and XFCE users may need different settings in .conkyrc.

For Kbuntu:

own_window yes
own_window_hints undecorated,below,skip_taskbar
background yes

Also, to get Conky to autostart in Kubuntu, add a link to the Conky bin file (in /usr/bin) in KDE's autostart file:

   ~/.kde/Autostart

For XFCE:

own_window yes
own_window_type override
own_window_transparent yes

For Compiz / AIGLX:

own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

Fortune's Word Wrapping is Wrong

Either change the font, use the "fold -sw" option, or see this

My Previous Cool Conky

My .conkyrc is based on the one above. Note that I have a Core Duo, so I have 2 cpu usage stats. Also, I've included stats on all of my partitions plus other disks on my local network.

I have a wide screen so Conky details sit nicely on the right hand side of the screen.


# UBUNTU-CONKY
#

# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# fiddle with window
use_spacer yes
use_xft no

# Update interval in seconds
update_interval 3.0

# Minimum size of text area
# minimum_size 250 5

# Draw shades?
draw_shades no

# Text stuff
draw_outline no # amplifies text if yes
draw_borders no
font arial
uppercase no # set to yes if you want all text to be in uppercase

# Stippled borders?
stippled_borders 3

# border margins
border_margin 9

# border width
border_width 10

# Default colors and also border colors, grey90 == #e5e5e5
default_color grey

own_window_colour brown
own_window_transparent yes

# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
gap_x 10
gap_y 20

# everything after 'TEXT' will be formatted on screen

TEXT
$color
${color orange}SYSTEM ${hr 2}$color
My < $nodename > $sysname $kernel on $machine
UPTIME:${color #606060} $uptime $color

${color orange}CPU ${hr 2}$color
${freq}MHz   Load: ${loadavg}   Temp: ${acpitemp}
TOTAL CPU:${color #606060} $cpu% ${cpubar}$color
    CPU 1:${color #606060} ${cpu cpu1}% ${cpubar cpu1}$color
    CPU 2:${color #606060} ${cpu cpu2}% ${cpubar cpu2}$color
${color #606060}${cpugraph 0000ff 00ec00}$color

NAME             PID       CPU%      MEM%
${color #606060}${top name 1} ${top pid 1}   ${top cpu 1}    ${top mem 1}
${top name 2} ${top pid 2}   ${top cpu 2}    ${top mem 2}
${top name 3} ${top pid 3}   ${top cpu 3}    ${top mem 3}
${top name 4} ${top pid 4}   ${top cpu 4}    ${top mem 4}${color} 

Processes:${color #606060} $processes $color Running:${color #606060} $running_processes

${color orange}MEMORY / DISK ${hr 2}$color
USAGE:${color #606060} ${fs_used /}/${fs_size /} - ${fs_used_perc /}% ${fs_bar /}${color} 
RAM:  ${color #606060} $mem/$memmax - $memperc% ${membar}${color} 
SWAP: ${color #606060} $swap/$swapmax - $swapperc% ${swapbar}${color} 

ROOT: ${color #606060} ${fs_free_perc /}%   ${fs_bar 6 /} $color
HOME: ${color #606060} ${fs_free_perc /home}%   ${fs_bar 6 /home}$color
USR:  ${color #606060} ${fs_free_perc /usr}%   ${fs_bar 6 /usr}$color
LOCAL:${color #606060} ${fs_free_perc /usr/local}%   ${fs_bar 6 /usr/local}$color
TMP:  ${color #606060} ${fs_free_perc /tmp}%   ${fs_bar 6 /tmp}$color
VAR:  ${color #606060} ${fs_free_perc /var}%   ${fs_bar 6 /var}$color

Windows: ${color #606060} ${fs_free_perc /media/Windows}%   ${fs_bar 6 /media/Windows}$color

server2_C: ${color #606060} ${fs_free_perc /media/server2_C}%   ${fs_bar 6 /media/server2_C}$color
server2_D: ${color #606060} ${fs_free_perc /media/server2_D}%   ${fs_bar 6 /media/server2_D}$color
server2_F: ${color #606060} ${fs_free_perc /media/server2_F}%   ${fs_bar 6 /media/server2_F}$color

${color orange}NETWORK (${addr eth0}) ${hr 2}$color
Down: $color${downspeed eth0}k/s ${alignr}Up: ${upspeed eth0}k/s
${downspeedgraph eth0 25,185 000000 ff0000} ${alignr}${upspeedgraph eth0 
25,185 000000 00ff00}$color
Total: ${totaldown eth0} ${alignr}Total: ${totalup eth0}
Inbound: ${tcp_portmon 1 32767 count} Outbound: ${tcp_portmon 32768 
61000 count}${alignr}Total: ${tcp_portmon 1 65535 count}

${color orange}MESSAGES ${hr 2}$color
${execi 30 tail -n3 /var/log/messages | fold -w50}

${color orange}APACHE ERROR ${hr 2}$color
${execi 30 tail -n2 /var/log/apache2/error.log | fold -w50}

${color orange}LITERARY QUOTES ${hr 2}$color
${execi 120 fortune 100% literature | fold -w50}

The result is similar to this:

Image:conky.png

Conky Problems After Hardy Upgrade

After an upgrade from Feisty to Hardy, Conky started truncating my text output. This had never been an issue before. Now all my log messages and longer fortune quotes were being cut at about the 130th character mark. I didn't know what was going on.

Some searching helped me find a solution to some extent, which was adding this:

   textt_buffer_size 512 

However, with some experimenting, I found it still truncates text. This is crap in my opinion. I don't know how to get it back to how it was, when it just output whatever was in the database file.

I also added xft plus "override_utf8_locale yes" to stop weird characters, such as the A you get with a degrees symbol. However, the text and font seems clearer without xft, but I'll stick with it for now.

Here's the new .conkyrc file.

# UBUNTU-CONKY
# A comprehensive conky script, configured for use on
# Ubuntu / Debian Gnome, without the need for any external scripts.
#
# Based on conky-jc and the default .conkyrc.
# INCLUDES:
# - tail of /var/log/messages
# - netstat connections to your computer
#

#### my additions since Hardy upgrade #####

text_buffer_size 1024
override_utf8_locale yes
use_xft yes
#xftfont MgOpen Modata-09
xftfont Bitstream arial:size=8
xftalpha 0.5
maximum_width 350

#####

# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# fiddle with window
use_spacer left

# Update interval in seconds
update_interval 3.0

# Minimum size of text area
#minimum_size 350 5

# Draw shades?
draw_shades no

# Text stuff
draw_outline no # amplifies text if yes
draw_borders no
#font arial
uppercase no # set to yes if you want all text to be in uppercase

# Stippled borders?
stippled_borders 3

# border margins
border_margin 9

# border width
border_width 10

# Default colors and also border colors, grey90 == #e5e5e5
default_color white

own_window_colour brown
own_window_transparent yes

# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
gap_x 10
gap_y 20


# everything after 'TEXT' will be formatted on screen

TEXT
$color
${color orange}SYSTEM ${hr 2}${color}
My cool < $nodename > $sysname $kernel on a $machine
UPTIME:${color     #888888} $uptime ${color}

${color orange}CPU ${hr 2}${color}

${freq}MHz   Load: ${loadavg}
TOTAL:${alignr 260}${color #888888} $cpu% ${cpubar}${color}
CPU 1:${alignr 260}${color #888888} ${cpu cpu1}% ${cpubar cpu1}${color}
CPU 2:${alignr 260}${color #888888} ${cpu cpu2}% ${cpubar cpu2}${color}
${color #888888}${cpugraph 0000ff 00ec00}$color

Core 0: ${execi 8 sensors | grep -A 1 'Core 0' | cut -c13-16 | sed '/^$/d'} °C ${color #888888} ${cpu core 0}% ${cpubar core 0}${color}
Core 1: ${execi 8 sensors | grep -A 1 'Core 1' | cut -c13-16 | sed '/^$/d'} °C ${color #888888} ${cpu core 1}% ${cpubar core 1}

${color orange}PROCESSES (No:${color #888888} $processes ${color orange}Running:${color #888888} $running_processes ${color orange}) ${hr 2}${color}

NAME                                   ${alignr 80}PID       CPU%     MEM%
${color #55ff55}${top name 1}    ${alignr 80}${top pid 1}     ${top cpu 1}      ${top mem 1}
${color #FF5555}${top name 2}    ${alignr 80}${top pid 2}     ${top cpu 2}      ${top mem 2}
${color #FFaa55}${top name 3}    ${alignr 80}${top pid 3}     ${top cpu 3}      ${top mem 3}
${color #FFff55}${top name 4}    ${alignr 80}${top pid 4}     ${top cpu 4}      ${top mem 4}

${color orange}MEMORY / DISK ${hr 2}$color

USAGE: ${color #888888} ${fs_used /}/${fs_size /} - ${fs_used_perc /}%  ${alignr 130}${fs_bar /}${color}
RAM: ${color #888888} $mem/$memmax - $memperc%  ${alignr 130}${membar}${color}
SWAP: ${color #888888} $swap/$swapmax - $swapperc%  ${alignr 130}${swapbar}${color}

ROOT: ${alignr 250}${color #888888} ${fs_free_perc /}%   ${fs_bar 6 /}${color}
HOME: ${alignr 250}${color #888888} ${fs_free_perc /home}%   ${fs_bar 6 /home}${color}
USR: ${alignr 250}${color #888888} ${fs_free_perc /usr}%   ${fs_bar 6 /usr}${color}
LOCAL: ${alignr 250}${color #888888} ${fs_free_perc /usr/local}%   ${fs_bar 6 /usr/local}${color}
TMP: ${alignr 250}${color #888888} ${fs_free_perc /tmp}%   ${fs_bar 6 /tmp}${color}
VAR: ${alignr 250}${color #888888} ${fs_free_perc /var}%   ${fs_bar 6 /var}${color}

Windows: ${alignr 250}${color #888888} ${fs_free_perc /media/Windows}%   ${fs_bar 6 /media/Windows}${color}

server2_C: ${alignr 250}${color #888888} ${fs_free_perc /media/server2_C}%   ${fs_bar 6 /media/server2_C}${color}
server2_D: ${alignr 250}${color #888888} ${fs_free_perc /media/server2_D}%   ${fs_bar 6 /media/server2_D}${color}
server2_F: ${alignr 250}${color #888888} ${fs_free_perc /media/server2_F}%   ${fs_bar 6 /media/server2_F}${color}

${color orange}NETWORK (${color #888888}${addr eth0}${color orange}) ${hr 2}${color}

Down: ${downspeed eth0}k/s ${alignr}Up: ${upspeed eth0}k/s
${color #888888}${downspeedgraph eth0 25,170 000000 ff0000} ${alignr}${upspeedgraph eth0
25,170 000000 00ff00}$color
Total: ${totaldown eth0} ${alignr}Total: ${totalup eth0}
Inbound: ${tcp_portmon 1 32767 count} Outbound: ${tcp_portmon 32768
61000 count}${alignr}Total: ${tcp_portmon 1 65535 count}

${color orange}MESSAGES ${hr 2}$color
${execi 30 tail -n1 /var/log/messages | fold -sw60}${font}

${color orange}APACHE ERRORS ${hr 2}$color
${execi 30 tail -n1 /var/log/apache2/error.log | fold -sw60}${font}

${color orange}LITERARY QUOTES ${hr 2}$color
${execi 120 fortune all | fold -sw60}${font}

In a way, it was a mixed blessing to have a few problems. I learned a lot more about Conky, including how to text wrap easily with the "fold -sw" output option.

Personal tools
KARA Logo