#!/usr/bin/perl use Getopt::Long; use Time::Local; my %opts = (); GetOptions(\%opts, "fs=s", "data=s", "user=s"); my $lastdate = ""; my @data = (); my $ld; print STDERR "fs = ", $opts{"fs"}, "\n"; print STDERR "user = ", $opts{"user"}, "\n"; print STDERR "data = ", $opts{"data"}, "\n"; while(<>) { my ($date, $fs, $user, $bused, $bsoft, $bhard, $iused, $isoft, $ihard) = split(/\t/); if ( ($opts{"fs"} ? $fs eq $opts{"fs"} : 1) && ($opts{"user"} ? $user eq $opts{"user"} : 1) ) { if ($date ne $lastdate) { if ($date =~ /(\d{4})-(\d{2})-(\d{2})T(\d{1,2}):(\d{2}):(\d{2})/) { $time = timelocal($6, $5, $4, $3, $2-1, $1-1900); } else { die "unparsable date $date\n"; } print "$date $time\n"; $ld = []; push(@data, [ $time, $ld ]); $lastdate = $date; } if ($data eq "b") { $ld = [ $bused, $bsoft, $bhard ]; } else { ... } } } my @top = (sort { ($ld->{$b} <=> $ld->{$a}) } (keys %$ld))[0..9]; print "@top\n"; open (DATA, ">quotastat.data") or die "cannot open quotastat.data for output: $!"; for (my $i = 0; $i <= $#data; $i++) { my $time = ($data[$i])->[0]; my $data = ($data[$i])->[1]; print DATA $time; for $j (@$data) { print DATA "\t", $j + 0; } print DATA "\n"; } close(DATA); open (CTL, ">quotastat.ctl") or die "cannot open quotastat.ctl for output: $!"; # generic settings print CTL "set term postscript color\n"; print CTL "set output 'quotastat.ps'\n"; print CTL "set data style lines\n"; print CTL "set grid\n"; # compute ticks my $firsttime = ($data[0])->[0]; my $lasttime = ($data[$#data])->[0]; if ($lasttime - $firsttime > 3 * 30 * 24 * 3600) { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; $mday = 1; $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); print CTL "set xtics rotate ("; $comma = 0; for (;;) { $time = timelocal($sec,$min,$hour,$mday,$mon,$year); if ($comma) { print CTL ", "; } else { $comma = 1; } printf CTL qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; if (++$mon >= 12) { $mon = 0; $year++; } if ($time > $lasttime) {last} } $lasttime = $time; print CTL ")\n"; } elsif ($lasttime - $firsttime > 30 * 24 * 3600) { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $firsttime -= 86400 * $wday; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; $time = $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); print CTL "set xtics rotate ("; $comma = 0; for (;;) { ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); if ($comma) { print CTL ", "; } else { $comma = 1; } printf CTL qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; if ($time > $lasttime) {last} $time += 7 * 24 * 3600; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); $toff = $hour * 3600 + $min * 60 * $sec; if ($toff != 0) { if ($toff > 12*3600) { $toff = 24 * 3600 - $toff; } print "correcting time by $toff seconds "; printf "from %04d-%02d-%02d %02d:%02d:%02d ", $year+1900, $mon+1, $mday, $hour, $min, $sec; $time -= $toff; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); printf "to %04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec; } } $lasttime = $time; print CTL ")\n"; } else { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; $time = $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); print CTL "set xtics rotate ("; $comma = 0; for (;;) { ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); if ($comma) { print CTL ", "; } else { $comma = 1; } printf CTL qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; if ($time > $lasttime) {last} $time += 24 * 3600; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); $toff = $hour * 3600 + $min * 60 * $sec; if ($toff != 0) { if ($toff > 12*3600) { $toff = 24 * 3600 - $toff; } print "correcting time by $toff seconds "; printf "from %04d-%02d-%02d %02d:%02d:%02d ", $year+1900, $mon+1, $mday, $hour, $min, $sec; $time -= $toff; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); printf "to %04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec; } } $lasttime = $time; print CTL ")\n"; } # what to plot print CTL "plot "; $comma = 0; $col = 2; for $i (@top) { if ($comma) { print CTL ", "; } else { $comma = 1; } print CTL "'quotastat.data' using 1:", $col++, " title '$i'"; } print CTL "\n"; close (CTL); my $rc = system("gnuplot", "quotastat.ctl"); print "system returned $rc\n"; system("gs -sDEVICE=ppmraw -r150 -dBATCH -sOutputFile=- -q - < quotastat.ps |" . "pnmscale 0.5 |" . "pnmflip -cw |" . "pnmcrop |" . "ppmquant 256 |" . "ppmtogif > quotastat.gif");