5 jpred_stats.pl - Collate Monthly and Daily usage statistics for the Jpred server
15 # path for nicer fonts for the graph labels
16 my $FONTPATH = "$ENV{HOME}/bin/fonts/";
21 my $file = '/grid/default/common/accounting';
25 'path=s' => \$outPath,
31 pod2usage(-verbose => 1) if $help;
32 pod2usage(-verbose => 2) if $man;
34 pod2usage(-msg => "$outPath doesn't exist please give a valid path", -verbose => 0) if (!-e $outPath);
36 my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
38 open (my $MONF, ">$outPath/monthly.csv") or die "ERROR - unable to open \'$outPath/monthly.csv\': $!";
39 open (my $DAYF, ">$outPath/daily.csv") or die "ERROR - unable to open \'$outPath/daily.csv\': $!";
44 my $currMon = extract_stats(\%stats, \%dayStats, $file);
48 #print "Monthly summary.\n";
49 ## Sort by and then by month and output/store usage data for each month
50 foreach my $yr (sort {$a <=> $b} keys %stats) {
51 #printf "\n%d\n", $yr + 1900;
52 foreach my $mon (sort {$a <=> $b} keys %{$stats{$yr}}) {
53 #print "$abbr[$mon]: $stats{$yr}{$mon}\n";
54 my $date = sprintf "%s %02d", $abbr[$mon], $yr-100;
55 print $MONF "$date,$stats{$yr}{$mon}\n";
56 $monthly[0][$i] = $date;
57 $monthly[1][$i] = $stats{$yr}{$mon};
61 draw_graph(\@monthly, 'Month', 'Monthly Breakdown of JNet Usage');
65 #print "\nDaily summary for $abbr[$currMon]\n";
66 ## Sort by date and ouput/store data for the current month.
67 foreach my $day (sort {$a <=> $b} keys %dayStats) {
68 #printf "%02d: %d\n", $day, $dayStats{$day};
69 printf $DAYF "%02d,%d\n", $day, $dayStats{$day};
71 $daily[1][$i] = $dayStats{$day};
74 die "ERROR - No data for current month ($abbr[$currMon])" if (!@daily);
75 draw_graph(\@daily, 'Date', "Daily Breakdown for $abbr[$currMon]");
79 foreach my $num (-7..-1) {
80 next if (!$daily[0][$num]);
81 $week[0][$i] = sprintf "%02d/%02d", $daily[0][$num], $currMon+1;
82 $week[1][$i] = $daily[1][$num];
85 draw_sm_graph(\@week);
89 my ($statsRef, $dayRef, $file) = @_;
91 open (my $FH, $file) or die "ERROR - can't open file \'$file\': $!";
93 my ($currMon, $currYr) = (localtime())[4,5];
96 next unless /www-jpred/;
97 my @F = split(/:/, $_);
98 die "ERROR - not enough fileds found in source file \'$file\'. Is the file correct and in the correct format?" if (9 > scalar @F);
99 #the 9th field is the date in Unix time. Extract the day, month and year from it.
100 my ($day, $mnth, $year) = (localtime($F[8]))[3..5];
101 next if ($year == 70); # ignore jobs with invalid dates
102 next if ($F[8] < 1148338800); # ignore jobs prior to 1 May 2006
104 if (($mnth == $currMon) && ($year == $currYr)) {
107 $statsRef->{$year}{$mnth}++;
110 die "ERROR - no valid data found in \'$file\'" unless $statsRef; # die if there's no data in $statsRef
116 my ($dataref, $x_label, $title) = @_;
118 my $graph = GD::Graph::bars->new(700, 400);
120 $graph->set_title_font("$FONTPATH/VeraBd.ttf", 12);
121 $graph->set_x_label_font("$FONTPATH/VeraBd.ttf", 8);
122 $graph->set_y_label_font("$FONTPATH/VeraBd.ttf", 8);
123 $graph->set_x_axis_font("$FONTPATH/Vera.ttf", 6);
124 $graph->set_y_axis_font("$FONTPATH/Vera.ttf", 8);
127 y_label => 'No. JNet Submissions',
131 x_labels_vertical => 1,
135 ) or die $graph->error;
137 my $gd = $graph->plot($dataref) or die $graph->error;
139 open(IMG, ">$outPath/jnet_${x_label}_stats.png") or die $!;
150 my $graph = GD::Graph::bars->new(250, 150);
152 $graph->set_y_label_font("$FONTPATH/VeraBd.ttf", 8);
153 $graph->set_x_axis_font("$FONTPATH/Vera.ttf", 8);
154 $graph->set_y_axis_font("$FONTPATH/Vera.ttf", 8);
156 y_label => 'No. Jobs',
157 x_labels_vertical => 1,
160 accentclr => 'lbrown',
161 dclrs => [ qw(dbrown dpurple) ],
163 ) or die $graph->error;
165 my $gd = $graph->plot($dataref) or die $graph->error;
167 open(IMG, ">$outPath/jnet_stats.png") or die $!;
177 jpred_stats.pl [--path <path>] [--source <file>]
181 Script to collate the usage statistics for the Jpred server. The stats are subdivided by month and then my day for he current month only.
183 The outputs are two graph images <jnet_Month_stats.png> and <jnet_Date_stats.png> and two comma separated files (<monthly.csv> and <daily.csv>) containing the raw data.
191 Path to where you want the output saved. [default: <current directory>]
193 =item --source <file>
195 Source of Sun Grid Engine usage log file. [default: /grid/default/common/accounting]
207 By default the script with use the current known SGE logfile and output the data to current directory.
211 Chris Cole <christian@cole.name>