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__

In reply to disk usage graph (dfgraph) by Fletch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.