This is a small script which we used to setup on our large cluster of webservers to see loadavg on terminal or putty title. This was very useful as you dont have to run top or w command to see what’s the current loadavg. It automatically updated the loadavg value every 2 seconds (it can be increased or decreased) on title of terminal or putty screen. Additionally it shows hostname and current time & date with loadavg.

We need to create small script with following code.

mkdir /scripts
vi /scripts/top.pl

#!/usr/bin/perl

use strict;
$|++;
my $host=`/bin/hostname`;
chomp $host;
while (1){
open (LOAD,”/proc/loadavg”) || die “could not open load avg: $! \n”;
my @load =split(/ /,);
close(LOAD);
print “\33]0;”;
print “$host: $load[0] $load[1] $load[2] at “, scalar(localtime);
print “\007″;
sleep 2;
}

save the script and give execute permission. Then put it in your .bashrc of your user that it can run on every login you do or open any new terminal.

chmod +x /scripts/top.pl
vi ~/.bashrc

at end put following line.

/scripts/top.pl &

Whenever you login into your linux server using putty or terminal you can see the following screen how it shows the information in title of terminal or putty.

putty_loadavg
pixelstats trackingpixel