Script to check the quota utilizations in ZFS

Script to check the quota utilizations in ZFS

#!/usr/local/bin/perl
use strict;


my $G = 1024 * 1024 * 1024;
my %warnings;


if(!(-e "/sbin/zpool")) {
        exit;
}


chomp(my @zpool_names = `zpool list -H -o name`);


if(@zpool_names eq "no datasets available") {
        exit;
}
else {
        print "\n                 ZFS zpool usage         \n";
        printf "%14.14s %9.9s %9.9s %9.9s %9.9s\n", "zpool","free","used", "quota","size";
        printf "%14.14s %9.9s %9.9s %9.9s %9.9s\n", "-----","----","----", "-----","----";
        for my $pool (@zpool_names) {
                chomp(my $free = `zfs get -o value -Hp available $pool`);
                chomp(my $used = `zfs get -o value -Hp used $pool`);
                my $size = $free + $used;
                my $quota = 0;
                my @quotas = `zfs get -o value -r -Hp quota $pool`;
                for (@quotas) {
                        $quota += $_;
                }
                printf "%14.14s %8.1fG %8.1fG %8.1fG %8.1fG", $pool, ($free/$G), ($used/$G), ($quota/$G), ($size/$G);
                if($quota > $size) {
                        print " WARNING quota > pool size\n";
                        $warnings{$pool} = "QUOTA";
                }
                else {
                        $warnings{$pool} = "none";
                        print "\n";
                }
        }
}


print "\n";
print " free: this is the unused space in the zpool\n";
print " used: this is the used space in the zpool\n";
print " quota: this is the sum of all the filesystem quotas in the zpool\n";
print " size: free+used\n";


for my $p (keys %warnings) {
        if($warnings{$p} eq "QUOTA") {
                print "\n WARNING: zpool $p has quota > pool size it is recommended that disk be added to the zpool before extending any filesystem quotas in the pool\n";
        }
}

Comments

Popular posts from this blog

Understanding How ZFS Calculates Used Space

How To Verify Remote System Controller (RSC) is Configured and Current on Sun Fire[TM] 280R/V480/V490/V880/V890 servers

Restart autosys agent