PATCH: add stats command to mogadm

Leon Brocard acme at astray.com
Thu Apr 19 16:48:41 UTC 2007


MogileFS::Admin exposes some nice stats. mogadm does not have an
interface to it. This patch rectifies the situation. On my two-node
test cluster it shows:

$  ./mymogadm --trackers=localhost:6001 stats

Fetching statistics...



Statistics for devices...

  device     host            files     status

  ---------- ----------- ---------- ----------

  dev1       cluster10       99890      alive

  dev5       cluster9        99889      alive

  ---------- ----------- ---------- ----------



Statistics for file ids...

  Max file id: 227138



Statistics for files...

  domain     class           files

  ---------- ----------- ----------

  resources  normal          99889

  ---------- ----------- ----------



Statistics for replication...

  domain     class        devcount      files

  ---------- ----------- ---------- ----------

  resources  normal              1          1

  resources  normal              2      99888

  ---------- ----------- ---------- ----------


What do you think?

Enjoy, Leon
-------------- next part --------------
--- mogadm	2007-04-19 17:27:48.000000000 +0100
+++ mymogadm	2007-04-19 17:46:01.000000000 +0100
@@ -12,6 +12,9 @@
     check => {
         des => "Check the state of the MogileFS world.",
     },
+    stats => {
+        des => "Show MogileFS system statistics.",
+    },
     host => {
         des => "Add/modify hosts.",
         subcmd => {
@@ -256,6 +259,9 @@
 if ($topcmd eq 'check') {
     die "Unknown options/arguments to 'check' command.\n" if @ARGV;
     cmd_check();
+} elsif ($topcmd eq 'stats') {
+    die "Unknown options/arguments to 'stats' command.\n" if @ARGV;
+    cmd_stats();
 }
 
 # get the verb
@@ -424,6 +430,50 @@
     ok();
 }
 
+sub cmd_stats {
+    print "Fetching statistics...\n";
+    my $stats = stats();
+    print "\nStatistics for devices...\n";
+    printf "  %-10s %-10s %10s %10s\n", "device", "host", "files", "status";
+    printf "  ---------- ----------- ---------- ----------\n";
+    foreach my $device (sort { $a <=> $b } keys %{$stats->{devices}}) {
+        my $value = $stats->{devices}->{$device};
+        printf "  %-10s %-10s %10s %10s\n", "dev$device", $value->{host}, $value->{files}, $value->{status};
+    }
+    printf "  ---------- ----------- ---------- ----------\n";
+    
+    print "\nStatistics for file ids...\n";
+    printf "  Max file id: %s\n", $stats->{fids}->{max};
+    
+    print "\nStatistics for files...\n";
+    printf "  %-10s %-10s %10s\n", 'domain', 'class', 'files';
+    printf "  ---------- ----------- ----------\n";
+    foreach my $domain (sort keys %{$stats->{files}}) {
+        my $classes = $stats->{files}->{$domain};
+        foreach my $class (sort keys %$classes) {
+            my $files = $classes->{$class};
+            printf "  %-10s %-10s %10s\n", $domain, $class, $files;
+        }
+    }
+    printf "  ---------- ----------- ----------\n";
+    
+    print "\nStatistics for replication...\n";
+    printf "  %-10s %-10s %10s %10s\n", 'domain', 'class', 'devcount', 'files';
+    printf "  ---------- ----------- ---------- ----------\n";
+    foreach my $domain (sort keys %{$stats->{replication}}) {
+        my $classes = $stats->{replication}->{$domain};
+        foreach my $class (sort keys %$classes) {
+            my $devcounts = $classes->{$class};
+            foreach my $devcount (sort { $a <=> $b } keys %$devcounts) {
+                my $files = $devcounts->{$devcount};
+                printf "  %-10s %-10s %10s %10s\n", $domain, $class, $devcount, $files;
+            }
+        }
+    }
+    printf "  ---------- ----------- ---------- ----------\n";
+    ok();
+}
+    
 sub cmd_host_list {
     my $hosts = hosts();
     fail_text('no_hosts') unless $hosts;
@@ -971,6 +1021,16 @@
     return $mogadm;
 }
 
+sub stats {
+    my $mogadm = shift() || mogadm();
+    my $res;
+    eval {
+        $res = $mogadm->get_stats();
+    };
+    return undef if $@;
+    return $res;
+}
+    
 sub hosts_byname {
     my $mogadm = shift() || mogadm();
     fail_text('no_mogadm') unless $mogadm;
@@ -1228,6 +1288,10 @@
 Check the status of your entire MogileFS system:
 
     $ mogadm check
+    
+Check MogileFS system statistics:
+
+    $ mogadm stats
 
 See all the things mogadm can do:
 
@@ -1256,6 +1320,8 @@
 
 Mark Smith E<lt>L<junior at danga.com>E<gt>
 
+Leon Brocard E<lt>L<acme at astray.com>E<gt>, open sourced permissions from Foxtons Ltd.
+
 =head1 BUGS
 
 Please report any on the MogileFS mailing list: L<http://lists.danga.com/mogilefs/>.


More information about the mogilefs mailing list