Gentoo Wiki ArchivesGentoo Wiki

Conky

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other


Please improve it in any way that you see fit, and remove this notice {{Cleanup}} from the article. For tips on cleaning and formatting see Cleanup process


Contents

Introduction

From the Conky FAQ: Conky is a program which can display arbitrary information (such as the date, CPU temperature from i2c, MPD info, and anything else you desire) to the root window in X11. Conky normally does this by drawing to the root window, however Conky can also be run in windowed mode (though this is not how conky was meant to be used).

An alternative to Conky, with some difference, is GKrellM.

Installation

Conky supports the following USE flags:

Check the default state of the flags of conky:

# emerge -pv conky

Then enter the flags you want to change into /etc/portage/package.use. For example if you want to disable ipv6 and infopipe and leave the rest alone:

File: /etc/portage/package.use
app-admin/conky -ipv6 -infopipe

Finally:

# emerge -av conky

General Configuration

conky has now been installed, but you probably want to configure it. This means editing the ~/.conkyrc file, and sometimes requires scripts to be installed. Some possibilities are given below.

This is based on a nice looking screenshot from the Conky website:

File: ~/.conkyrc
background              no
use_xft                 yes
xftfont                 terminius:size=12
double_buffer           yes
update_interval         2
alignment               top_left
gap_x                   10
gap_y                   10
no_buffers              yes
minimum_size            265x400
pad_percents            3

TEXT
${color #ffcb48}$nodename$color ${color #98c2c7}$sysname $kernel on $machine$color
${color #ffcb48}PROCESSING$color

${color #98c2c7}CPU:$color $cpu%
${color #78af78}$cpubar
${color #78af78}${cpugraph 78af78 a3a3a3}

${color #98c2c7}NAME             PID       CPU%      MEM%
${color #e5e5e5}${top name 1} ${top pid 1}   ${top cpu 1}    ${top mem 1}
${color #c4c4c4}${top name 2} ${top pid 2}   ${top cpu 2}    ${top mem 2}
${color #a3a3a3}${top name 3} ${top pid 3}   ${top cpu 3}    ${top mem 3}
${color #828282}${top name 4} ${top pid 4}   ${top cpu 4}    ${top mem 4}

${color #ffcb48}DATA$color

${color #98c2c7}RAM:$color     $memperc%         ${color #78af78}${membar 6}${color}
${color #98c2c7}Swap:$color     $swapperc%         ${color #78af78}${swapbar 6}$color

${color #98c2c7}NAME             PID       CPU%      MEM%
${color #e5e5e5}${top_mem name 1}     ${top_mem pid 1}  ${top_mem cpu 1}      ${top_mem mem 1}
${color #c4c4c4}${top_mem name 2}  ${top_mem pid 2}  ${top_mem cpu 2}      ${top_mem mem 2}
${color #a3a3a3}${top_mem name 3}${top_mem pid 3}   ${top_mem cpu 3}     ${top_mem mem 3}
${color #828282}${top_mem name 4} ${top_mem pid 4}  ${top_mem cpu 4}     ${top_mem mem 4}

${color #ffcb48}SPACE$color

${color #98c2c7}root:$color     ${fs_free_perc /}%  ${fs_free /}  ${color #78af78}${fs_bar 6 /}$color
${color #98c2c7}home:$color     ${fs_free_perc /home}%  ${fs_free /home}  ${color #78af78}${fs_bar 6 /home}$color

${color #ffcb48}NET$color

${color #98c2c7}eth0
${color #98c2c7}DOWN: ${color #ffffff}${downspeed eth0} k/s         ${color #98c2c7}UP: ${color #ffffff}${upspeed eth0} k/s
${color #98c2c7}${downspeedgraph eth0 25,100 78af78 a3a3a3}       ${color #98c2c7}${upspeedgraph eth0 25,100 78af78 a3a3a3}
${color #98c2c7}TOTAL: ${color #ffffff}${totaldown eth0}                ${color #98c2c7}TOTAL: ${color #ffffff}${totalup eth0}

Adding Portage Information

NOTE: The following scripts require read permission on /var/log/emerge.log, and other portage-specific files. It may be best to add your user (or the user running these scripts) into the portage group with something like:

gpasswd -a <user> portage

Simply changing /var/log/emerge.log to 644 won't work, as portage appears to change the permissions of this log file back to 660 after it logs anything into it (as of 2006.1).

Be aware that users in the portage group can write to PORTDIR (where the package files are stored), PKGDIR (where binary packages are stored), DISTDIR (where source files are stored) and the location where packages currently being compiled are stored. You must trust anyone you add to the portage group completely.

Last sync

You can check the timestamp of your last sync by adding this to the TEXT section of ~/.conkyrc:

File: ~/.conkyrc
${execi 180 cat /usr/portage/metadata/timestamp.chk}


If you are using /usr/bin/qlop which is part of app-portage/portage-utils you can use it this way:

File: ~/lastsync.sh
#!/bin/bash
qlop -s |sed 's/\ >>>.*//' |tail -n 1 |xargs -i date --date="{}" '+%A %_d.%B %Y'  # format of time, i like it this way; use man date for inspiration

Then:

 chmod 755 ~/lastsync.sh

And then adding:

File: ~/.conkyrc
Last sync: ${execi 300 ~/lastsync.sh}


Or the time that you last sync'd according to emerge.log using this python script:

File: ~/lastsync.py
#!/usr/bin/python
# 
# prints the last time portage was updated (locatime)
# prints something like "Monday at 6:52pm (Sep 12)"
# man strftime for more varibles in time display

import time

for line in file('/var/log/emerge.log'):
    if 'Sync completed' in line:
        lastline = line

print time.strftime("%A at %l:%M%P (%b %d)", time.localtime(int(lastline[:10])))

Then:

chmod 775 ~/lastsync.py

And then adding:

File: ~/.conkyrc
Last sync: ${execi 300 /usr/local/bin/lastsync.py}

someplace in the TEXT section of ~/.conkyrc.

Adding the last 5 emerged packages

You need to emerge app-portage/genlop for this:

# emerge -av genlop

Then add this line to your ~/.conkyrc:

File: ~/.conkyrc
${execi 50 genlop -lnu | sed -e 's/.*\([><]\+\)/\1/' | tail -n 5}


You can also use app-portage/portage-utils:

 # emerge -av app-portage/portage-utils
File: ~/.conkyrc
${execi 50 qlop -lC | tail -n 5 | sed 's/.*>>>\ //'}

Showing the current package

This also needs app-portage/genlop:

# emerge -av genlop

And then add this to your ~/.conkyrc:

File: ~/.conkyrc
${execi 50 if pgrep sandbox > /dev/null ; then genlop -cn ; else echo there is currently no package compiling; fi}

Adding XMMS Information

Note: XMMS has been removed from portage, and thus the xmms use flag has been removed from conky. You'll have to compile it yourself if you want XMMS support.

I've found this for torsmo on the gentoo forums. I'll take it over from there.

You need the media-plugins/xmms-infopipe plugin for XMMS.

# emerge -av xmms-infopipe

Fire up XMMS and enable the plugin, found in Preferences  General Plugins.

Play a song and verify xmms-info (symlink), xmms-info_$USERNAME.0, and xmms_$USERNAME.0 exist in /tmp.

To see the current song type this into your console:

cat /tmp/xmms-info

Install the XMMS::InfoPipe perl module if you don't already have it:

File: xmms.pl
#!/usr/bin/perl
# Perl script to display XMMS song info on Torsmo
# Requires XMMS::InfoPipe module and xmms-infopipe plugin

use XMMS::InfoPipe;

my $numArgs = $#ARGV+1;

if($numArgs != 1) {
   print "Usage error: xmms.pl [keyname]\n";
   exit;
}

else {
   my $key = $ARGV[0];
   my $xmms = XMMS::InfoPipe->new();
   my $playing = $xmms->is_playing();
   my $paused = $xmms->is_paused();

   # display info since XMMS is playing/paused
   if($playing == 1 || $paused == 1) {

      # extract song artist
      if($key eq "Artist") {
         my $title = $xmms->{info}->{Title};
         @song = split(/ - /, $title);
         my $artist = $song[0];

         #truncate long artist names
         if(length($artist) >= 30) {
            my $temp = substr($artist, 0, 30);
            $artist = $temp . "...";
         }
         print $artist , "\n";
      }

      # extract song title
      elsif($key eq "Title") {
         my $title = $xmms->{info}->{Title};
         @song = split(/ - /, $title);
         print $song[1] , "\n";      
      }

      # join position and length times, ie 2:04 / 4:50
      elsif($key eq "Time") {
         my $length = $xmms->{info}->{Time};
         my $position = $xmms->{info}->{Position};
         print $position , " / " , $length , "\n";
      }

      # format bitrate, ie 192 kbps
      elsif($key eq "Bitrate") {
         my $bitrate = $xmms->{info}->{"Current bitrate"};
         print $bitrate/1000 , " kbps\n";
      }

      # number of tunes in playlist
      elsif($key eq "Playlist") {
         my $tunes = $xmms->{info}->{"Tunes in playlist"};
         print $tunes , " tunes\n";
      }

      # print out info for other keys (case sensitive, 'cat /tmp/xmms-info')
      else {
         print $xmms->{info}->{$key} , "\n";
      }
   }

   # display status only since XMMS is not playing/paused
   else {
      if($key eq "Status") {
         print $xmms->{info}->{Status} , "\n";
      }
   }
}

Add these lines to the TEXT section of ~/.conkyrc. Change accordingly.

File: ~/.conkyrc
${color #ffcb48}XMMS$color

${color #98c2c7}Status    :  $color${execi 10 perl /place-to-the-script/xmms.pl Status}
${color #98c2c7}Title        :  $color${execi 10 perl /place-to-the-script/xmms.pl Title}
${color #98c2c7}Artist      :  $color${execi 10 perl /place-to-the-script/xmms.pl Artist}
${color #98c2c7}Bitrate    :  $color${execi 10 perl /place-to-the-script/xmms.pl Bitrate}
${color #98c2c7}Time       :  $color${execi 10 perl /place-to-the-script/xmms.pl Time}

Adding ping information

This idea originally came from gdesklets. You can use it to check if your server is still online by adding the following to the TEXT section of ~/.conkyrc:

File: ~/.conkyrc
${color #ffcb48}PING$color ${color #98c2c7}<your server here>

${color}${texeci 50 sh -c "ping -q -c5 <your server here> | tail -n 2" }

Another approach

Here's another idea, short and nice info of which hosts are up.

File: /usr/local/bin/silentping.sh
#!/bin/bash
if  [["$#" != "3"]] ; then echo "Usage: silentping IP onsign offsign"; fi
echo -n "$(ping $1 -c 1 -w 1 | grep packets | sed "s/^.*tted, //;s/1/$2/;s/0/$3/;s/ re.*$//")"

Then chmod 775 /usr/local/bin/silentping.sh
And then add to ~/.conkyrc

File: ~/.conkyrc
${color grey}Hosts:
$color${texeci 150 silentping.sh <HOST1ADDR> "host1up" "host1down"}
$color${texeci 150 silentping.sh <HOST2ADDR> "host2up" "host2down"}

Yet Another Approach

This is an extension of the idea above which adds color depending on the status of the host.

File: /usr/local/bin/silentping.sh
m#!/bin/bash
if  [["$#" != "3"]] ; then echo "Usage: silentping IP onsign offsign"; fi

# Get the status
STATUS="$(ping $1 -c 1 -w 2 | grep packets | sed "s/^.*tted, //;s/1/$2/;s/0/$3/;s/ re.*$//")"

# Create the directory
if [ ! -d ~/.status ]; then mkdir ~/.status; fi

# Remove the old status
if [ "$STATUS" == "$2" ]; then
  if [ -f ~/.status/$1.$3 ]; then rm ~/.status/$1.$3; fi
else
  if [ -f ~/.status/$1.$2 ]; then rm ~/.status/$1.$2; fi
fi

# Create the new status file
if [ ! -f ~/.status/$1.$STATUS ]; then touch ~/.status/$1.$STATUS; fi

I recommend playing around with the formatting to have multiple hosts on the same line to save space.

File: ~/.conkyrc
${color #ffcb48}HOSTS$color
${color #98c2c7}<HOSTNAME>: ${texeci 150 silentping.sh <HOSTIP> "up" "down"}${if_existing /home/<USERNAME>/.status/<HOSTIP>.up}${color green}+++$else${color red}---$endif

Adding Torsmo Scripts

You can also use most Torsmo scripts with Conky. The following scripts were found on the TIP torsmo page.

IMAP Email Checking Script

This method uses ruby:

File: checkimap.rb
#! /usr/bin/env ruby
# by Ardanwen

require "net/imap"
require "base64"

imap = Net::IMAP.new("your server here")
imap.login("your username here",Base64.decode64("your encrypted password here"))
imap.select("inbox")
value = imap.search(["NOT","SEEN"])
if value.empty? == false
   printf "#{value.nitems} new mail!"
else
   printf "No new mail"
end
imap.disconnect


For gmail you need to change the line imap = Net... to:

File:
imap = Net::IMAP.new("imap.gmail.com","993","true")

In order to generate an obfuscated version of your password, paste the following line into a console, edit checkimap to contain your obfuscated password and then save and chmod +x it:

Code:
ruby -e "require 'base64';puts Base64.encode64('your password here')"

Add ${execi 180 checkimap.rb} to the TEXT part of your ~/.conkyrc file to display the number of unread emails on your imap server.

Current User Count

To count the number of currently logged in users, use this :

File: ~/.conky_users
#!/bin/sh
who | awk '{print $1}' | uniq -c | wc -l

Make the file executable:

chmod 775 ~/.conky_users

Then, in the TEXT section of your ~/.conkyrc file, you can place ${execi 8 ~/.conky_users} to show the current number of logged in users.

See also

Retrieved from "http://www.gentoo-wiki.info/Conky"

Last modified: Sun, 12 Oct 2008 03:39:00 +1100 Hits: 40,758

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.