Monday, May 31, 2010

Script to Monitor ClearCase license

Here are the scripts mentioned in my previous post regarding monitoring ClearCase license usage.

re: http://doublepaddle.blogspot.com/2008/02/monitoring-clearcase-license-usage.html Apperently I am not good at following up my previous posts -- Sorry for the delay.


The collection script is as simple as this.

#!/usr/bin/sh
date >> /home/ccadmin/logs/license.log
/opt/rational/clearcase/bin/clearlicensegrep "Current active users" >> /home/ccadmin/logs/license.log

The script is scheduled in cron jobs for every 10 mintues. This script can be easily converted to a Windows batch file and added to scheduler.

Then a perl script is used to load the data and generate the report in excel format. The script can be added as part of the Windows scheduler, or run at the time when you want to view the report. The nice chart in the previous post is also part of the excel report.

#!/usr/bin/perl
#Auther: Li Qin
#Date: 2008.02.05
#Function: generate ClearCase license usage report in excel format

use Spreadsheet::WriteExcel;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

$Win32::OLE::Warn = 3; # die on errors...

$file = "C:\\Li\\SCM\\ClearCase\\report-licns.xls";
$workbook = Spreadsheet::WriteExcel->new("$file");
$sheet = $workbook->addworksheet("data");

my $format1 = $workbook->add_format();
$format1->set_bold();
$format1->set_size(15);
$format1->set_color('blue');
$format1->set_align('center');

my $format2 = $workbook->add_format();
$format2->set_bold();
$format2->set_size(11);
$format2->set_color('Black');
$format2->set_align('center');

my $format3 = $workbook->add_format();
$format3->set_size(11);
$format3->set_color('Black');
$format3->set_align('center');

$sheet->activate();
$sheet->merge_range('C2:G2', "ClearCase Usage Report", $format1);

$sheet->set_column(3, 2, 40);
$sheet->set_column(3, 3, 20);
$sheet->set_column(3, 4, 20);
$sheet->write(3, 2, "Date", $format2 );
$sheet->write(3, 3, "Usage", $format2 );
$sheet->write(3, 4, "Max", $format2 );

open(FILE,"license.log")  || die "couldn't open file a.out";
$row = 4;
my @user1, @user2;
$max = 35;
while ($date= ) {
chomp $date;

$line1 = ;
chomp $line1;
while ( !($line1 =~ m/Current/) ) {
$user1[$row-4] = 0;

$sheet->write($row+1, 2, $date, $format3);
$sheet->write($row+1, 3, $user1[$row-4], $format3);
if ( $date =~ m/Fri Feb 1 17/ ) {
$max = 40;
}
$sheet->write($row+1, 4, $max, $format3);
$row = $row +1;
$date = $line1;
$line1 = ;
chomp $line1;
}
$pos = rindex $line1, ":";
$user1[$row-4] = substr($line1,$pos+1);
$user1[$row-4]=$user1[$row-4]+0;

$sheet->write($row+1, 2, $date, $format3);
if ( $date =~ m/Fri Feb 1 17/ ) {
$max = 40;
}
$sheet->write($row+1, 3, $user1[$row-4], $format3);
$sheet->write($row+1, 4, $max, $format3);
$row = $row +1;
}
close(FILE);
$workbook->close;

# #create chart
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');

# open Excel file
my $Book = $Excel->Workbooks->Open("$file");
# select worksheet of data


$count = 6;
my $sheet = $Book->Worksheets("data");
my $value = $sheet->Cells($count,4)->{'Value'};
my $len = length($value);

while ( $len >0 ) {
$count = $count +1;
my $value = $sheet->Cells($count,4)->{'Value'};
$len = length($value);
#printf "At ($count, 4) the value is %s. length is %d\n", $value, $len;
}
print "last row is $count.";


$lastRow = $count-1;
my $Range = $sheet->Range("C6:E$lastRow");

my $Chart2 = $Excel->Charts->Add($sheet);
$Chart2->{ChartType} = xlLine;
$Chart2->SetSourceData({Source => $Range, PlotBy => xlColumns});

$Chart2->{HasTitle} = 1;
$Chart2->ChartTitle->{Text} = "ClearCase License Usage\n";
$Chart2->Axes(xlValue)->{HasTitle} = 1;
$Chart2->Axes(xlValue)->AxisTitle->{Text} = "License Usage";
$Chart2->Axes(xlCategory)->{HasTitle} = 1;
$Chart2->Axes(xlCategory)->AxisTitle->{Text} = "Date/Time";

$Chart2->{HasLegend} = 'False';
$Chart2->{Name} = "Chart";
$Chart2->{HasLegend} = 1;
$Chart2->Legend->{Position} = xlBottom;
$Chart2->SeriesCollection(1)->{Name} = "Usage";
$Chart2->SeriesCollection(2)->{Name} = "Max";

# save and clean up
$Book->Save;
$Book->Close;
# End of create charts

We have upgraded our monitoring using SQL Server Reporting Service, a nice-to-have.

5 comments:

Anonymous said...

I advise to you.

Anonymous said...

whoah this blog is fantastic i love reading your articles.
Stay up the good work! You already know, a lot of individuals are hunting around for this info, you could aid them greatly.


Take a look at my web blog ... legal amphetamines

Anonymous said...

Apρreсiating the perѕistence yοu put into
youг blοg anԁ detailеd іnformatiоn уou providе.
It's good to come across a blog every once in a while that isn't the same unwantеd гehаshed informatіоn.
Excellеnt read! I've saved your site and I'm including уоur RSЅ feеds to my Google
account.

Мy blοg: 50 state legal incense reviews

Anonymous said...

I loved as much as you'll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike.

My page: cheap legal highs

Anonymous said...

I'm not sure exactly why but this website is loading extremely slow for me. Is anyone else having this problem or is it a issue on my end? I'll check back later and see if the problem still exists.


Here is my blog ... cheap legal highs