How To Display Loadavg on Terminal/Putty Title

on August 9 | in Linux, Programming / Scripting | by | with 5 Comments

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
Pin It

related posts

5 Responses to How To Display Loadavg on Terminal/Putty Title

  1. sagar says:

    Hello.
    i copied it and pasted in vi editor but its not working coz
    the symbols (” and “) are interpreted as and sometimes . so how do i paste it to make it working?

  2. A Osama says:

    Not working here either.

  3. @Osama: I think the copy&paste from my blog changes the qoutes and other symbols to other when pasting on your system. I will upload it in a file in txt form. In meanwhile you can correct it by just copying to any text editor and fix the symbol which changes.

  4. WillCroPoint says:

    True, fixed the pasted quotes and works fine, awesome, thanks for the nice script!

    Also, I guess the split call may be changed to:
    my @load=split(/ /,);

  5. WillCroPoint says:

    Arg, HTML parsing…:
    my @load=split(/ /,);

Leave a Reply

Your email address will not be published. Required fields are marked *

« »