In a similar vein to disk monitor, I had this lying around. It parses the output from df to produce a bar graph of disk usage. Term::ANSIColor is used to highlight partitions that are really full (85% or more) or almost full (75-85%).
1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0 0 Filesystem (avail) ---|---|---|---|---|---|---|---|---|---| ------------------ 89 =================================== /dos (704936) 62 ======================== /usr (4555040) 62 ======================== /home/lemur (4555040) 45 ================== / (134353)
Tested on Linux, FreeBSD, OpenBSD, and Solaris.
#!/usr/bin/perl use Term::ANSIColor qw( color ); my @lines; my $df = "df"; ## Point to a Berkely-esque df if needed if ($^O =~ /solaris/) { $df = "/usr/ucb/df"; } ## Open a pipe from df open( DF, "$df @ARGV |" ) or die "Can't open pipe from df: $!"; ## skip first line scalar <DF>; ## Print header print " 1\n", " 1 2 3 4 5 6 7 8 9 0\n", " 0 0 0 0 0 0 0 0 0 0 Filesystem (avail +)\n", " ---|---|---|---|---|---|---|---|---|---| ----------------- +-\n"; ## Parse output from df while(<DF>) { chomp; my @F = split; $_ .= <DF>, @F = split if @F == 1; my( $av, $c, $fs ) = @F[3, 4,-1]; $c =~ s/(\d+)%/$1/; push @lines, [ $c, sprintf "%3d %-40s %s (%d)", $c, "=" x int($c / 2.5), $fs, $av ]; } close(DF); ## Print sorted reverse by capacity for( sort { $b->[0] <=> $a->[0] } @lines ) { my $color = ''; if ( $_->[0] >= 85 ) { $color = color( 'bold red' ); } elsif ( $_->[0] >= 70 ) { $color = color( 'bold yellow' ); } print $color, $_->[1], color('reset'), "\n"; } exit 0; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: disk usage graph (dfgraph)
by belg4mit (Prior) on Nov 17, 2001 at 06:10 UTC | |
by Fletch (Bishop) on Nov 17, 2001 at 06:55 UTC | |
|
Re: disk usage graph (dfgraph)
by AltBlue (Chaplain) on Nov 20, 2001 at 21:55 UTC | |
|
Re: disk usage graph (dfgraph)
by coec (Chaplain) on Mar 02, 2002 at 11:38 UTC |