Index: /trunk/Nebulous-Server/bin/neb-volstat
===================================================================
--- /trunk/Nebulous-Server/bin/neb-volstat	(revision 12983)
+++ /trunk/Nebulous-Server/bin/neb-volstat	(revision 12983)
@@ -0,0 +1,205 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2005  Joshua Hoblitt
+#
+# $Id: neb-volstat,v 1.1 2007-04-24 04:26:17 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+use DBI;
+use Nebulous::Server::SQL;
+use URI;
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version );
+use Pod::Usage qw( pod2usage );
+
+my ($db, $dbuser, $dbpass, $name, $uri);
+
+$db     = $ENV{'NEB_DB'} unless $db;
+$dbuser = $ENV{'NEB_USER'} unless $dbuser;
+$dbpass = $ENV{'NEB_PASS'} unless $dbpass;
+
+GetOptions(
+    'db=s'      => \$db,
+    'user=s'    => \$dbuser,
+    'pass=s'    => \$dbpass,
+) || pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
+    unless $db && $dbuser && $dbpass;
+
+my $dbh = DBI->connect(
+    "DBI:mysql:database=$db:host=localhost",
+    $dbuser,
+    $dbpass,
+    {
+        RaiseError => 1,
+        PrintError => 0,
+        AutoCommit => 1,
+    },
+);
+
+my $sql = Nebulous::Server::SQL->new();
+
+#my $query = $dbh->prepare( $sql->get_storage_status );
+
+my $query = $dbh->prepare("select * from volume");
+$query->execute();
+
+my $mount_query = $dbh->prepare("select *, instr(?, mountpoint) = 1 as substring from mount order by substring desc, length(mountpoint) desc limit 1");
+
+my @stats;
+
+while (my $volume_row = $query->fetchrow_hashref) {
+    $mount_query->execute($volume_row->{path});
+    my $mount_row = $mount_query->fetchrow_hashref;
+
+    my $vol = {%{$volume_row}, %{$mount_row}};
+    push @stats, $vol;
+
+#    use Data::Dumper;
+#    print Dumper($vol);
+}
+
+print "Filesystem           1K-blocks      Used Available Use% Mounted on\n";
+
+foreach my $vol (@stats) {
+    my $path        = $vol->{path};
+    my $total       = $vol->{total};
+    my $used        = $vol->{used};
+    my $available   = $total - $used;
+    my $usedper     = ($used / $total) * 100; 
+    my $mountpoint  = $vol->{mountpoint};
+
+    # indicated the part of the nebulous volume name that matches up with a
+    # local volume (mountpoint) 
+    #$path =~ s/$mountpoint/[$mountpoint]/;
+
+    # printf formats taken from df.c in coreutils-6.7
+    # Copyright (C) 91, 1995-2006 Free Software Foundation, Inc.
+
+    if (length $path > 20) {
+        printf ("%s\n%20s", $path, "");
+    } else {
+        printf ("%-20s", $path);
+    }
+
+    printf(" %*s %*s %*s %*.0f%% %s\n",
+            9,
+            $total,
+            9,
+            $used,
+            9,
+            $available,
+            3,
+            $usedper,
+            $mountpoint,
+        );
+}
+
+__END__
+
+=pod
+
+=head1 NAME
+
+neb-volstat - provide `df` like summary of nebulous volumes
+
+=head1 SYNOPSIS
+
+    neb-volstat [--db <database>] [--user <username>] [--pass <password>]
+
+=head1 DESCRIPTION
+
+This program outputs a list of Nebulous volumes and various metadata about
+them.  It attempts to conform to the format of data output by the GNU version
+of C<df> when passed the C<-k> flag. E.g. C<df -k>
+
+=head1 OPTIONS
+
+=over 4
+
+=item * --db|-d <database>
+
+Name of database (C<namespace>) to retreive metadata from.
+
+Optional if the appropriate environment variable is set.
+
+=item * --user|-u <username>
+
+Username to authenticate with.
+
+Optional if the appropriate environment variable is set.
+
+=item * --pass|-p <password>
+
+Password to authenticate with.
+
+Optional if the appropriate environment variable is set.
+
+=back
+
+=head1 ENVIRONMENT
+
+These environment variables may be used in place of the specified command line
+options.  All command line option will override the corresponding environment
+value.
+
+=over 4
+
+=item * C<NEB_DB>
+
+Equivalent to --db|-d
+
+=item * C<NEB_USER>
+
+Equivalent to --user|-u
+
+=item * C<NEB_PASS>
+
+Equivalent to --pass|-p 
+
+=back
+
+=head1 CREDITS
+
+Just me, myself, and I.
+
+=head1 SUPPORT
+
+Please contact the author directly via e-mail.
+
+=head1 AUTHOR
+
+Joshua Hoblitt <jhoblitt@cpan.org>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2007  Joshua Hoblitt.  All rights reserved.
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA  02111-1307, USA.
+
+The full text of the license can be found in the L<perlgpl> Pod as supplied
+with Perl 5.8.1 and later.
+
+=head1 SEE ALSO
+
+L<Nebulous::Server>, L<neb-initdb>, L<neb-addvol>, L<nebdiskd>
+
+=cut
Index: /trunk/Nebulous/bin/neb-volstat
===================================================================
--- /trunk/Nebulous/bin/neb-volstat	(revision 12983)
+++ /trunk/Nebulous/bin/neb-volstat	(revision 12983)
@@ -0,0 +1,205 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2005  Joshua Hoblitt
+#
+# $Id: neb-volstat,v 1.1 2007-04-24 04:26:17 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+use DBI;
+use Nebulous::Server::SQL;
+use URI;
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version );
+use Pod::Usage qw( pod2usage );
+
+my ($db, $dbuser, $dbpass, $name, $uri);
+
+$db     = $ENV{'NEB_DB'} unless $db;
+$dbuser = $ENV{'NEB_USER'} unless $dbuser;
+$dbpass = $ENV{'NEB_PASS'} unless $dbpass;
+
+GetOptions(
+    'db=s'      => \$db,
+    'user=s'    => \$dbuser,
+    'pass=s'    => \$dbpass,
+) || pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
+    unless $db && $dbuser && $dbpass;
+
+my $dbh = DBI->connect(
+    "DBI:mysql:database=$db:host=localhost",
+    $dbuser,
+    $dbpass,
+    {
+        RaiseError => 1,
+        PrintError => 0,
+        AutoCommit => 1,
+    },
+);
+
+my $sql = Nebulous::Server::SQL->new();
+
+#my $query = $dbh->prepare( $sql->get_storage_status );
+
+my $query = $dbh->prepare("select * from volume");
+$query->execute();
+
+my $mount_query = $dbh->prepare("select *, instr(?, mountpoint) = 1 as substring from mount order by substring desc, length(mountpoint) desc limit 1");
+
+my @stats;
+
+while (my $volume_row = $query->fetchrow_hashref) {
+    $mount_query->execute($volume_row->{path});
+    my $mount_row = $mount_query->fetchrow_hashref;
+
+    my $vol = {%{$volume_row}, %{$mount_row}};
+    push @stats, $vol;
+
+#    use Data::Dumper;
+#    print Dumper($vol);
+}
+
+print "Filesystem           1K-blocks      Used Available Use% Mounted on\n";
+
+foreach my $vol (@stats) {
+    my $path        = $vol->{path};
+    my $total       = $vol->{total};
+    my $used        = $vol->{used};
+    my $available   = $total - $used;
+    my $usedper     = ($used / $total) * 100; 
+    my $mountpoint  = $vol->{mountpoint};
+
+    # indicated the part of the nebulous volume name that matches up with a
+    # local volume (mountpoint) 
+    #$path =~ s/$mountpoint/[$mountpoint]/;
+
+    # printf formats taken from df.c in coreutils-6.7
+    # Copyright (C) 91, 1995-2006 Free Software Foundation, Inc.
+
+    if (length $path > 20) {
+        printf ("%s\n%20s", $path, "");
+    } else {
+        printf ("%-20s", $path);
+    }
+
+    printf(" %*s %*s %*s %*.0f%% %s\n",
+            9,
+            $total,
+            9,
+            $used,
+            9,
+            $available,
+            3,
+            $usedper,
+            $mountpoint,
+        );
+}
+
+__END__
+
+=pod
+
+=head1 NAME
+
+neb-volstat - provide `df` like summary of nebulous volumes
+
+=head1 SYNOPSIS
+
+    neb-volstat [--db <database>] [--user <username>] [--pass <password>]
+
+=head1 DESCRIPTION
+
+This program outputs a list of Nebulous volumes and various metadata about
+them.  It attempts to conform to the format of data output by the GNU version
+of C<df> when passed the C<-k> flag. E.g. C<df -k>
+
+=head1 OPTIONS
+
+=over 4
+
+=item * --db|-d <database>
+
+Name of database (C<namespace>) to retreive metadata from.
+
+Optional if the appropriate environment variable is set.
+
+=item * --user|-u <username>
+
+Username to authenticate with.
+
+Optional if the appropriate environment variable is set.
+
+=item * --pass|-p <password>
+
+Password to authenticate with.
+
+Optional if the appropriate environment variable is set.
+
+=back
+
+=head1 ENVIRONMENT
+
+These environment variables may be used in place of the specified command line
+options.  All command line option will override the corresponding environment
+value.
+
+=over 4
+
+=item * C<NEB_DB>
+
+Equivalent to --db|-d
+
+=item * C<NEB_USER>
+
+Equivalent to --user|-u
+
+=item * C<NEB_PASS>
+
+Equivalent to --pass|-p 
+
+=back
+
+=head1 CREDITS
+
+Just me, myself, and I.
+
+=head1 SUPPORT
+
+Please contact the author directly via e-mail.
+
+=head1 AUTHOR
+
+Joshua Hoblitt <jhoblitt@cpan.org>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2007  Joshua Hoblitt.  All rights reserved.
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA  02111-1307, USA.
+
+The full text of the license can be found in the L<perlgpl> Pod as supplied
+with Perl 5.8.1 and later.
+
+=head1 SEE ALSO
+
+L<Nebulous::Server>, L<neb-initdb>, L<neb-addvol>, L<nebdiskd>
+
+=cut
