IUBio Biosequences .. Software .. Molbio soft .. Network News .. FTP

GCG accounting

jun at nih.go.jp jun at nih.go.jp
Wed Jul 15 21:18:02 EST 1998


Dear Nick,

In article <8DD3D27DC6A5D111823200A0C955FB4004CC88 at drucker.niehs.nih.gov> staffa at niehs.nih.gov ("Staffa.Nick") writes:

> I've been logging  GCG usage for the past month on our Unix box.
> It would be nice to be able to run a script or program to 
> condense this data and produce a report -- even a
> list of programs run and how many times, or whatever.
> If you have developed such a script,  would you please be
> so kind, friendly, helpful and generous as to send same to me for 
> my use.  

I'm using the attached Perl script. The script reads gcg.log
from the standard input and writes to the standard output:

% gcgstat.pl < gcg.log > out.html

You can browse the output by using your browser.

Regards,

--
ISHIKAWA Jun, Ph.D.            Natl. Inst. of Infectious Diseases
(jun at nih.go.jp)                Dept. of Bioactive Molecules
AUCUCCCACAUCAAAGCUUGGGCU       Tokyo 162-8640, JAPAN
http://www.nih.go.jp/~jun/research/ 
-------------- next part --------------
#!/usr/local/bin/perl

$TITLE =	'GCGStat.pl';
$COPYRIGHT =	'Copyright (c) 1998, ISHIKAWA Jun';
$AUTHOR =	'<a href="mailto:jun at nih.go.jp">jun at nih.go.jp</a>';
$DATE =		'\$Date: 1998/07/16 02:17:08 $';

$MANUAL = 'http://watson.nih.go.jp/~gcg/man';

# initialize variables
$totaljobs = 0;			# total number of jobs
$totaltimes = 0;		# total time of jobs
%Command = ();			# by command
%User = ();			# by user
%Hour = ();			# by hour
%Date = ();			# by day
%Type = ();			# by type

while (<STDIN>) {
    ($com,$user,$group,$host,$type,$os,$date,$hour,$sec) = split;
    next if $user eq "gcg"; # exclude System Manager
    $Command{$com} += $sec; $CommandNum{$com}++;
    $User{$user} += $sec;   $UserNum{$user}++;
    $Date{$date} += $sec;   $DateNum{$date}++;
    $hour =~ /([0-9]+):[0-9]+/o;
    $Hour{$1} += $sec; $HourNum{$1}++;
    $Type{$type} += $sec; $TypeNum{$type}++;
    $totaljobs++;
    $totaltimes += $sec;
}

@SortedDate = sort keys %Date;

print "<h1>GCG Version 9.1 Usage Statistics<a href=\"#footnote\">*</a></h1>\n";
print "<h4>Period: $SortedDate[0] - $SortedDate[$#SortedDate]<br>\n";
print "    Total Job: $totaljobs<br>\n";
$temp = sprintf "%.2f",&minutes($totaltimes);
print "    Total Time: $temp min\n";
print "</h4>\n";

for $item ("User","Command","Hour","Date","Type") {
    &output($item);
}

print "<hr>\n";
print <<"FOOTNOTE";
<a name="footnote">*</a>
This statistics were produced by GCGStat.pl,
$COPYRIGHT ($AUTHOR).
FOOTNOTE

#
# subroutines
#
sub output {
    my($tem1,$ItemNum,$JobRate,$SecRate, at array);
    $Item = $_[0];
    $ItemNum = $Item."Num";
    $separator = "-" x 50;
    print "<h3>Summary by $Item</h3>\n";
    print "<pre>\n";
    print $separator,"\n";
    printf "%16s %5s %3s %13s%4s\n",$Item,"Job","(%)","Min","(%)";
    print $separator,"\n";

    $_ = $Item;
    SWITCH: {
	(/^Command/ || /^User/ || /^Type/) && do {
	    @array = sort {
		$$ItemNum{$b} <=> $$ItemNum{$a} || $$Item{$b} <=> $$Item{$a}
	    } keys %$ItemNum;
	    last SWITCH; };
	/^Hour/ && do {
	    @array = sort {$a <=> $b} keys %$Item;
	    last SWITCH; };
	/^Date/ && do {
	    @array = sort {$a cmp $b} keys %$Item;
	    last SWITCH; };
	@array = keys %$Item;
    }

    for (@array) {
	$JobRate = $$ItemNum{$_} / $totaljobs * 100;
	$SecRate = $$Item{$_} / $totaltimes * 100;
	$buf = sprintf "%16s %5d (%4.1f) %10.2f (%4.1f)\n",
		$_,$$ItemNum{$_},$JobRate,&minutes($$Item{$_}),$SecRate;
	if ($Item eq "Command") {
	    $buf =~ s#$_#<a href=\"$MANUAL/$_.html\">$_<\/a>#;
	}
	print $buf;
    }
    print $separator,"\n";
    if ($Item eq "Type") {
	print "B: Batch job (containing W2H)\n";
	print "I: Interactive execution (Xterm, DXterm, telnet etc.)\n";
	print "W: Window environment (SeqLab)\n";
    }
    print "</pre>\n";
}

sub minutes {
    my $min = $_[0] / 60;
    return $min;
}


More information about the Info-gcg mailing list

Send comments to us at biosci-help [At] net.bio.net