Conky

From Gentoo Linux Wiki

Jump to: navigation, search

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.

Contents

[edit] Installation

Conky supports the following USE flags:

  • X: Support for X. Enable it or you can only use conky on the terminal!
  • audacious: Conky can monitor the tracks this program is playing if you enable this flag. Only enable it if you use this program.
  • hddtemp: Conky can monitor the temperature of your hard drives if you enable this flag. Only enable it if you use Hddtemp.
  • infopipe: Conky can monitor the tracks this program is playing if you enable this flag. Only enable it if you use this program.
  • ipv6:Support for IPv6. Enable if you use it (if you don't know what this is then you are not using it).
  • mpd:Conky can monitor the tracks this program is playing if you enable this flag. Only enable it if you use this program.
  • nano-syntax:Includes a .conkyrc syntax file for nano. Only enable it if you use nano.
  • rss: Enables support for RSS feeds.
  • smapi: Enables support for smapi.
  • truetype:Support for FreeType and/or FreeType2 fonts. Enable it if you want more (nice) fonts.
  • vim-syntax:Includes a .conkyrc syntax file for vim. Only enable it if you use vim.
  • wifi: Enables wireless network functions.

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:

echo "app-admin/conky -ipv6 -infopipe" >> /etc/portage/package.use

Finally:

emerge -av conky

[edit] Configuration

The file used for configuration is ~/.conkyrc. You can find some cute examples on Conky's screen shot page.

[edit] Display Portage Information

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.

Warning: 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.

[edit] 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 syncronized 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|<pre>
Last sync: ${execi 300 /usr/local/bin/lastsync.py}

someplace in the TEXT section of ~/.conkyrc.


[edit] Determine Presence of Package Updates

This will delay conky's startup as emerge has to run and report it's findings, but for some may be worth it. First, make sure your system is entirely up-to-date.

emerge -vuaDN system world


Then execute this command to make your reference file. This is the file the script will check against to see if there are any package updates. This file should be called ~/.noupdate

File: ~/.noupdate
emerge -vupDN system world | grep Total >> ./.noupdate


Next, create this script.

File: ~/.checkupdates.sh
#!/bin/sh

rm ./.noupstat
emerge -vupDN system world | grep Total >> ./.noupstat
if diff ./.noupstat ./.noupdate >/dev/null; then
  echo No Updates
else
  echo Updates Available
fi


And, of course:

chmod 0777 ~/.checkupdates


Place the script in your conky config, and when it launches, it'll create a file and output the total number of packages. If the packages are equal to zero, you don't need to update any packages. That's what the reference file was for.

[edit] Show latest changes to the portage tree for your arch

From packages.gentoo.org:

File: ~/.conkyrc
${texeci 240 curl -s http://packages.gentoo.org/feed/arch/amd64 | sed -n '/span/ s/.*>\([^ ]*\)<.*/\1/p' | head -n 20}

Adjust the URL to display your arch. See: http://packages.gentoo.org/faq/

Including overlays from gpo.zugaina.org:

File: ~/.conkyrc
${texeci 240 curl -s http://gpo.zugaina.org/RSS/Newest/ | sed -n '/title/ s/.*>\([^ ]*\)<.*/\1/p'}

Note that parsing rss with sed is considered ugly. New versions of conky (post 1.8.0) have a dedicated ${rss} object.

[edit] List the Last Five 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/.*>>>\ //'}


[edit] Display the Current Emerge

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}

[edit] Display 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" }

[edit] 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"}

[edit] 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
#!/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

[edit] And one more

#!/bin/bash
#author sla237
#Used by conky. Colorize host status. 
# Usage ./conky_ping.sh [ip|dnsName] DisplayName
addr=$1

up="\${color green}" # color of UP host
down="\${color red}" #color of DOWN host
cla="\${color green}"  #set color back, after colorizing   CLA-CoLorAfter

if `ping $addr -c 1 -w 2 &> /dev/null`; then 
		echo -n $up$2$cla
	else
		echo -n $down$2$cla
	fi;
${execpi 10 ~/bin/conky_ping.sh "127.0.0.1" "localhost"}

[edit] Troubleshooting

[edit] Problems on GNOME

Conky is not really compatible with Nautilus. Nautilus draws directly on your desktop, and conky wants to do so, too. But there are workarounds:

File: ~/.conkyrc
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,skip_taskbar,skip_pager

[edit] More information

More information is available at the conky wiki.

Personal tools