simple/quotacheck/quotagraph

195 lines
5.2 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/perl -w
use strict;
2001-07-16 09:46:17 +02:00
use Getopt::Long;
use Time::Local;
my %opts = ();
GetOptions(\%opts, "fs=s", "data=s", "user=s");
my $lastdate = "";
my @data = ();
print STDERR "fs = ", $opts{"fs"}, "\n";
print STDERR "user = ", $opts{"user"}, "\n";
print STDERR "data = ", $opts{"data"}, "\n";
sub usage {
print STDERR "Usage: $0 --fs=<filesystem> --user=<username> --data=[bi]\n";
exit(1);
}
2001-07-16 09:46:17 +02:00
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) {
my $time;
2001-07-16 09:46:17 +02:00
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";
my $ld;
if ($opts{data} eq "b") {
$ld = [ $bused, $bsoft, $bhard ];
} elsif ($opts{data} eq "i") {
$ld = [ $iused, $isoft, $ihard ];
} else {
usage();
}
2001-07-16 09:46:17 +02:00
push(@data, [ $time, $ld ]);
$lastdate = $date;
}
}
}
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 my $j (@$data) {
print DATA "\t", $j + 0;
2001-07-16 09:46:17 +02:00
}
print DATA "\n";
}
close(DATA);
open (CTL, ">quotacheck.ctl") or die "cannot open quotacheck.ctl for output: $!";
2001-07-16 09:46:17 +02:00
# 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) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime);
2001-07-16 09:46:17 +02:00
$sec = $min = $hour = 0;
$mday = 1;
$firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year);
print CTL "set xtics rotate (";
my $comma = 0;
my $time;
2001-07-16 09:46:17 +02:00
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) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime);
2001-07-16 09:46:17 +02:00
$firsttime -= 86400 * $wday;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime);
$sec = $min = $hour = 0;
my $time = $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year);
2001-07-16 09:46:17 +02:00
print CTL "set xtics rotate (";
my $comma = 0;
2001-07-16 09:46:17 +02:00
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);
my $toff = $hour * 3600 + $min * 60 * $sec;
2001-07-16 09:46:17 +02:00
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 {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime);
2001-07-16 09:46:17 +02:00
$sec = $min = $hour = 0;
my $time = $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year);
2001-07-16 09:46:17 +02:00
print CTL "set xtics rotate (";
my $comma = 0;
2001-07-16 09:46:17 +02:00
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);
my $toff = $hour * 3600 + $min * 60 * $sec;
2001-07-16 09:46:17 +02:00
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 qq{plot "quotastat.data" using 1:2 title "used", "quotastat.data" using 1:3 title "soft", "quotastat.data" using 1:4 title "hard"\n};
2001-07-16 09:46:17 +02:00
close (CTL);
my $rc = system("gnuplot", "quotacheck.ctl");
2001-07-16 09:46:17 +02:00
print "system returned $rc\n";
my $fs = $opts{fs};
$fs =~ s|/|_|g;
2001-07-16 09:46:17 +02:00
system("gs -sDEVICE=ppmraw -r150 -dBATCH -sOutputFile=- -q - < quotastat.ps |" .
"pnmscale 0.5 |" .
"pnmflip -cw |" .
"pnmcrop |" .
"ppmquant 256 |" .
"ppmtogif >/usr/local/www/wsr/intranet/quotas/$opts{user}$fs.gif");