#!/usr/bin/perl -w # df-analyze v0.10, a script to analyze log files of the format: # df for MM.DD # # This is free software, released in the hope that it will be useful, # but without even the WARRANTY OF MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. Let me say it again: NO WARRANTY AT ALL. This # script *should* be perfectly safe, but if something bad happens, then # the person running this script is responsible for running it. # You are free to use this software in any manner you see fit. License # to modify and redistribute this work is given under the GNU GPL, # available at http://www.gnu.org/copyleft/gpl.html. # # In other words, if it breaks, you get to keep both pieces. # Copyright 2000, Bill Jonas, with assistance from Chris Fearnley (text # formatting and output). # Right now, the only argument that this script takes is a filename, and # that's required. @ARGV || die "Specify a file\n"; @ARGV eq 1 || die "Oops!\nUsage: $0 \n"; open (FILE, "$ARGV[0]") || die "Can't open file: $!"; # Let's get the stuff that's not going to change out of the way, so we # don't keep reassigning it over and over ; SETUP: while () { if (/^\/dev\/(\w+)\s+(\d+)\s+\d+\s+\d+\s+\d{1,3}%\s+(\/[^\s]*$)/) { # (Device) (Total) Used Available Capacity% (Mountpoint) $dfmaster{$1}{total}=$2; $dfmaster{$1}{mountpoint}="$3"; } elsif (/^df for \d\d\.\d\d$/) { last SETUP; } } seek (FILE,0,0); # Back to the beginning of the file # Set things up so that the comparisons later will work foreach $filesystem (keys %dfmaster) { $dfmaster{$filesystem}{maxused}=-1; $dfmaster{$filesystem}{minused}=undef; # Nicer than assigning it some } # arbitrarily large value. # Thanks to michael@toren.net. # Set up a few housekeeping variables for gathering stats: $totaldays=0; $today=0; # Now, let's get our stats while () { if (/^\/dev\/(\w+)\s+\d+\s+(\d+)\s+(\d+)\s+(\d{1,3})%\s+\/[^\s]*$/) { # (Device) Total (Used) (Available) (Capacity)% Mountpoint $dfmaster{$1}{total_used}+=$2; $dfmaster{$1}{total_avail}+=$3; $dfmaster{$1}{total_used_pct}+=$4; if ($2 > $dfmaster{$1}{maxused}) { $dfmaster{$1}{maxused}=$2; $dfmaster{$1}{dayofmax}=$today; } unless (defined $dfmaster{$1}{minused}) { $dfmaster{$1}{minused}=$2; $dfmaster{$1}{dayofmin}=$today; } elsif ($2 < $dfmaster{$1}{minused}) { $dfmaster{$1}{minused}=$2; $dfmaster{$1}{dayofmin}=$today; } } elsif (/^df for (\d\d\.\d\d)$/) { $totaldays++; $today=$1; } } foreach $filesystem (keys %dfmaster) { foreach $item ("used","avail","used_pct") { $dfmaster{$filesystem}{"avg_$item"}=$dfmaster{$filesystem}{"total_$item"} / $totaldays; } } # foreach $filesystem (sort keys %dfmaster) { # print "$filesystem: "; # foreach $item (sort keys %{ $dfmaster{$filesystem}}) { # print "$item=$dfmaster{$filesystem}{$item} "; # } # print "\n"; # } print "Mount Device Capacity Range of Daily Avg % Used\n"; print "Point Space Used Space Used \n"; print "-----------------------------------------------------------------------\n"; foreach $filesystem (sort keys %dfmaster) { printf("%-9s %-8s %8sK %8sK-%-sK %8.0fK %2.2f%%\n", $dfmaster{$filesystem}{'mountpoint'}, $filesystem, $dfmaster{$filesystem}{'total'}, $dfmaster{$filesystem}{'minused'}, $dfmaster{$filesystem}{'maxused'}, $dfmaster{$filesystem}{'avg_used'}, (($dfmaster{$filesystem}{'avg_used'})/$dfmaster{$filesystem}{'total'})*100); } __END__ sda1: avg_avail=923993.583333333 avg_used=81930.375 avg_used_pct=9.125 dayofmax=08.24 dayofmin=08.16 maxused=131055 minused=59671 mountpoint=/ total=1018298 total_avail=22175846 total_used=1966329 total_used_pct=219 sda6: avg_avail=2461132.25 avg_used=668371.916666667 avg_used_pct=22.6666666666667 dayofmax=08.24 dayofmin=08.18 maxused=830988 minused=610222 mountpoint=/usr total=3168186 total_avail=59067174 total_used=16040926 total_used_pct=544