From b39a4ebfbdd6f8ad50085f92287410b3958399f7 Mon Sep 17 00:00:00 2001 From: hjp Date: Mon, 16 Jul 2001 07:46:17 +0000 Subject: [PATCH] Added quotagraph_* to repository. --- quotacheck/quotagraph | 196 ++++++++++++++++++++++++++++++++++++ quotacheck/quotagraph_bused | 9 ++ 2 files changed, 205 insertions(+) create mode 100755 quotacheck/quotagraph create mode 100755 quotacheck/quotagraph_bused diff --git a/quotacheck/quotagraph b/quotacheck/quotagraph new file mode 100755 index 0000000..49d9d9d --- /dev/null +++ b/quotacheck/quotagraph @@ -0,0 +1,196 @@ +#!/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; + } + $ld->{$user . $fs} = $bused if ($opts{"data"} eq "bused"); + $ld->{$user . $fs} = $bsoft if ($opts{"data"} eq "bsoft"); + $ld->{$user . $fs} = $bhard if ($opts{"data"} eq "bhard"); + $ld->{$user . $fs} = $iused if ($opts{"data"} eq "iused"); + $ld->{$user . $fs} = $isoft if ($opts{"data"} eq "isoft"); + $ld->{$user . $fs} = $ihard if ($opts{"data"} eq "ihard"); + } +} + +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 (@top) { + print DATA "\t", $data->{$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"); diff --git a/quotacheck/quotagraph_bused b/quotacheck/quotagraph_bused new file mode 100755 index 0000000..073fa5c --- /dev/null +++ b/quotacheck/quotagraph_bused @@ -0,0 +1,9 @@ +#!/bin/sh +if [ $# -ne 2 ] +then + echo "Usage: $0 user fs" >&2 + exit 1 +fi +./quotagraph --user=$1 --fs=$2 --data=bused \ + `ls /usr/local/dfstat/quota.stat.* | tail -12` +mv quotastat.gif $1.gif