APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Girish Venkatachalam > Server monitoring with Conky
Printer Friendly Version




Conky




Girish Venkatachalam

Girish Venkatachalam is a UNIX hacker with more than a decade of networking and crypto programming experience. His hobbies include yoga,cycling, cooking and he runs his own business. Details here:

http://gayatri-hitech.com
http://spam-cheetah.com

Network monitoring is big business. There is a company in Chennai that has a famous product for network monitoring. That product has been a cash cow for them even after they built several other business lines with that money.

It continues to fill their coffers though I am not sure how much they get out of it month after month.

Any good product should fetch good money but unfortunately the world does not work that way. Certain products in certain domains get you more money than arguably much better products in some other domain.

Ultimately people pay you when they need your offering and when your offering either offers them a price advantage or a technology advantage.

The other way to look at it is this:

"Either you should improve their profits or cut down their costs."

If you can keep this goal in mind and give your customer anything that helps them achieve this goal you succeed.

By the way I heard these words many years past from a business owner.

Anyway now let us get back on track and focus on UNIX and technology. This site is after all for technology though you can get advice on related matters like this.

I had to do server monitoring for one of my clients and I ended up using the sexy conky tool for it.

But I had to do a lot of jugglery to make it work on the web.

You need a conkyrc ~/.conkyrc that looks like this:

# maintain spacing between certain elements
use_spacer none

# set to yes if you want tormo to be forked in the background
background yes

use_xft no

# Xft font when Xft is enabled
#xftfont Bitstream Vera Sans Mono-8
#xftfont Andale Mono-9
#xftfont Clean-8
xftfont Times New Roman
#xftfont squaredance10:pixelsize=14
#xftfont swf!t_v02:pixelsize=10

# Text alpha when using Xft
#xftalpha 1
#mail_spool $MAIL

# Update interval in seconds
update_interval 1.0

# Create own window instead of using desktop (required in nautilus)
own_window yes
default_color brown

own_window_colour brown
own_window_transparent yes

own_window_hints undecorated,below,skip_taskbar,skip_pager
#own_window_type normal

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

# Minimum size of text area
minimum_size 280 5

# Draw shades?
draw_shades no

# Draw outlines?
draw_outline no # amplifies text

# Draw borders around text
draw_borders yes

# Stippled borders?
stippled_borders 3
font verdana

# border margins
border_margin 9

# border width
border_width 1

# Default colors and also border colors, grey90 == #e5e5e5
default_color red
default_shade_color brown
default_outline_color DarkGrey

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

# Gap between borders of screen and text
gap_x 810
gap_y 30

# Subtract file system buffers from used memory?
no_buffers yes

# set to yes if you want all text to be in uppercase
#uppercase yes

#$alignc${color turquoise}${diskiograph log 30, 120 0066cc 99cc00 sd0} 
#$alignc${color turquoise}${diskiograph log 30, 120 0066cc 99cc00 wd0} 
# stuff after 'TEXT' will be formatted on screen
# $alignc${color brown}${downspeedgraph eth0 30,130 99ff00 ff3300} ${color brown}${upspeedgraph eth0 30, 130 0fffff de0fff }



TEXT
$alignc${color green}$sysname $kernel $machine
$alignc${color green}Uptime:$color $uptime ${color green} Load:$color $loadavg

$alignc${color #ffffff}${time}$color

$alignc${color orange}CPU:$color ${cpu }% ${color green}${cpubar 10,100} 

$alignc${color brown}${cpugraph log 30, 120 0066cc 99cc00} 

$alignc${color green}RAM:$color $mem / $memmax ${color orange} ${membar 10, 120} $memperc%

$alignc${color green}IP Address:$color${addr eth0}
${color green}Down:$color${downspeed eth0}k/s${color green}${offset 65}Up:$color${upspeed eth0}k/s
$alignc${color white}${downspeedgraph eth0 30,130 99ff00 ff3300} ${color brown}${upspeedgraph eth0 30, 130 0fffff de0fff }
${color white}Root: ${fs_used_perc /}% ${fs_bar 10 /}
/data: ${fs_used_perc /data}% ${fs_bar 10 /data}
/san1: ${fs_used_perc /san1}% ${fs_bar 10 /san1}
/san2: ${fs_used_perc /san2}% ${fs_bar 10 /san2}
/san3: ${fs_used_perc /san3}% ${fs_bar 10 /san3}$color

$alignc${color green}[Top - Processes]$color

$alignc${color #ffffff}Name               PID   CPU%  MEM%
$alignc${color green}${top name 1}${top pid 1}${top cpu 1}${top mem 1}
$alignc${color #ffffff}${top name 2}${top pid 2}${top cpu 2}${top mem 2}
$alignc${color #ffffff}${top name 3}${top pid 3}${top cpu 3}${top mem 3}
$alignc${color #ffffff}${top name 4}${top pid 4}${top cpu 4}${top mem 4}
$alignc${color #ffffff}${top name 5}${top pid 5}${top cpu 5}${top mem 5}

$alignc${color green}[Top - Memory]$color

$alignc${color #ffffff}Name               PID   CPU%  MEM%
$alignc${color green}${top_mem name 1}${top_mem pid 1}${top_mem cpu 1}${top_mem mem 1}
$alignc${color #ffffff}${top_mem name 2}${top_mem pid 2}${top_mem cpu 2}${top_mem mem 2}
$alignc${color #ffffff}${top_mem name 3}${top_mem pid 3}${top_mem cpu 3}${top_mem mem 3}
$alignc 50 ${color #ffffff}${top_mem name 4}${top_mem pid 4}${top_mem cpu 4}${top_mem mem 4}
$alignc${color #ffffff}${top_mem name 5}${top_mem pid 5}${top_mem cpu 5}${top_mem mem 5}

$alignc${color lightblue}${execi 30 /usr/bin/fortune -s | fold -w52 }$color
 

Then I needed this script to make conky write to a fake X server Xvfb.

-sh-3.2$ cat conky-setup
#!/bin/sh

# This script will not only start conky but also refresh the image
every 5 seconds

# Watch the fun ;)

Xvfb :5 -screen 0 1280x1024x24&

export DISPLAY=:5.0
xsetroot -solid lightslateblue
conky  2>/tmp/f.txt
sleep 3

windowid=`grep 0x /tmp/f.txt|cut -d\( -f2|tr -d \)`
while [ "1" = "1" ];
do
        import -window ${windowid} /san1/sysadmin/navigator/conky.png
        sleep 3
done
 

As you can see I used the ImageMagick convert(1) command to get Xlib window output to a file. Conky cannot directly write to an image file.

I start this script manually with

$./conky-setup&
 

Or you can put it in ~/.profile. Your choice.

The best place would be to put in system startup script. But conky can be used by any user and it displays what is mentioned in ~/.conkyrc.

No need to use root privileges when you don't need them. First rule of UNIX.

I needed to display this on the web with cycle transitions.

I chose a jQuery slideshow plugin for the following reasons:

  1. Everytime the image loads, there is annoying blankness shown on the page.
  2. The flicker in image reloading can only be avoided by image preloading but cycle plugin offers that and animations too.

Using animations is not a good idea in serious business but that is no blanket truth. You can when there is a need as long as you don't annoy the user.

I do image preloading with the cycle callback onBefore. Here is the html.

-sh-3.2$ cat conky.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "<A HREF="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</A>>
        <!-- -->
<head>
        <title> Monitoring dashboard for Storkmon </title>
        <!-- Active content -->
<!-- ************************************************************************
-->

<link rel="stylesheet" href="css/tailf.css" type="text/css"/>

<script type="text/javascript" src="jquery/js/jquery-1.3.2.min.js"> </script>
<script type="text/javascript" src="jquery/js/jquery.metadata.js"> </script>
<script type="text/javascript"
src="jquery/js/jquery.cycle.lite.1.0.js"> </script>
<script type="text/javascript" >

function onBefore() {
        $('img').load("/cgi-bin/conky-display.cgi");
}
$(function() {
                //setInterval(reloadpage, 4000);
        $('#taildiv').cycle({
                speed: 500,
                before: onBefore
        });
});
</script>
</head>
<body>
<div id="taildiv">
        <img  />
        <img />
</div>

</body>
</html>
 

Wth this beautiful result:

http://lamp.healthsoftusa.com/conky.html

(If that doesn't work, try http://lamp.healthsoftusa.com/cgi-bin/conky-display.cgi)

Even with all this conky's root window output on X cannot be matched.


If this page was useful to you, please click to help others find it:  
Your +1's can help friends, contacts, and others on the web find the best stuff when they search.


Comments?




More Articles by Girish Venkatachalam



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


cartoon

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide




Buy Kerio from a dealer who knows tech: I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals