root / plugins / disk / btrfs_subvol_usage @ 6c7ad652
Historique | Voir | Annoter | Télécharger (2,06 ko)
| 1 | 11e4124c | Alexander Knöbel | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | |||
| 3 | =head1 NAME |
||
| 4 | |||
| 5 | btrfs_subvol_usage - Plugin to monitor usage of BTRFS subvolumes |
||
| 6 | |||
| 7 | =head1 CONFIGURATION |
||
| 8 | |||
| 9 | Must be run as root and you have to specify the path to the filesystem |
||
| 10 | |||
| 11 | 09b88141 | Lars Kruse | [btrfs_usage] |
| 12 | user root |
||
| 13 | env.fsroot /path/to/btrfs/filesystem |
||
| 14 | 11e4124c | Alexander Knöbel | |
| 15 | =head1 MAGIC MARKERS |
||
| 16 | |||
| 17 | #%# family=auto |
||
| 18 | #%# capabilities=autoconf |
||
| 19 | |||
| 20 | =head1 USAGE |
||
| 21 | |||
| 22 | 17f78427 | Lars Kruse | Link/Copy this plugin to /etc/munin/plugins/ and restart the munin-node. |
| 23 | |||
| 24 | 11e4124c | Alexander Knöbel | =head1 AUTHOR |
| 25 | |||
| 26 | Alexander Knöbel <alex@belogy.de> |
||
| 27 | |||
| 28 | =head1 LICENSE |
||
| 29 | |||
| 30 | GPLv2 |
||
| 31 | |||
| 32 | =cut |
||
| 33 | |||
| 34 | use strict; |
||
| 35 | use Munin::Plugin; |
||
| 36 | |||
| 37 | if ($ARGV[0] and $ARGV[0] eq 'autoconf') {
|
||
| 38 | if (-e "/sbin/btrfs") {
|
||
| 39 | print "yes\n"; |
||
| 40 | } else {
|
||
| 41 | print "no (/sbin/btrfs is missing)\n"; |
||
| 42 | } |
||
| 43 | exit 0; |
||
| 44 | } |
||
| 45 | |||
| 46 | my @fsroot; |
||
| 47 | if ( !defined( $ENV{"fsroot"} ) ) {
|
||
| 48 | die "No fsroot given! See the manual at top of this plugin file."; |
||
| 49 | } |
||
| 50 | @fsroot = $ENV{"fsroot"};
|
||
| 51 | |||
| 52 | # get subvolumes |
||
| 53 | my %subvols; |
||
| 54 | open(SVS, "btrfs subvolume list --sort=path @fsroot |") |
||
| 55 | or die("Failed to run 'btrfs subvolume list': " . $!);
|
||
| 56 | while (my $line = <SVS>) {
|
||
| 57 | chomp $line; |
||
| 58 | $line =~ s/ID ([0-9]+) gen ([0-9]+) top level ([0-9]+) path (.+)//; |
||
| 59 | $subvols{$1}->{id} = $1;
|
||
| 60 | $subvols{$1}->{name} = $4;
|
||
| 61 | } |
||
| 62 | close SVS; |
||
| 63 | |||
| 64 | # get sizes from quota |
||
| 65 | 735689d4 | rantal | open(QGS, "btrfs qgroup show --raw @fsroot |") |
| 66 | 11e4124c | Alexander Knöbel | or die("Failed to run 'btrfs qgroup show': " . $!);
|
| 67 | while (my $line = <QGS>) {
|
||
| 68 | chomp $line; |
||
| 69 | $line =~ s|([0-9]+)/([0-9]+)\s+([0-9]+)\s+([0-9]+)||; |
||
| 70 | if (defined($2) && defined($subvols{$2})) {
|
||
| 71 | $subvols{$2}->{rfer} = $3;
|
||
| 72 | $subvols{$2}->{excl} = $4;
|
||
| 73 | } |
||
| 74 | } |
||
| 75 | close QGS; |
||
| 76 | |||
| 77 | # print config |
||
| 78 | if ($ARGV[0] and $ARGV[0] eq 'config') {
|
||
| 79 | print "btrfs_usage\n"; |
||
| 80 | print "graph_title BTRFS Subvolume usage\n"; |
||
| 81 | print "graph_args --base 1024 --lower-limit 0\n"; |
||
| 82 | print "graph_vlabel Bytes\n"; |
||
| 83 | print "graph_category disk\n"; |
||
| 84 | |||
| 85 | for my $id (sort { $subvols{$a}->{name} cmp $subvols{$b}->{name} } keys %subvols) {
|
||
| 86 | print "$id.label " . $subvols{$id}->{name} . "\n";
|
||
| 87 | print "$id.type GAUGE\n"; |
||
| 88 | print "$id.draw LINE2\n"; |
||
| 89 | } |
||
| 90 | |||
| 91 | exit 0; |
||
| 92 | } |
||
| 93 | |||
| 94 | # print usage |
||
| 95 | print "btrfs_subvol_usage\n"; |
||
| 96 | for my $id (sort { $subvols{$a}->{name} cmp $subvols{$b}->{name} } keys %subvols) {
|
||
| 97 | print "$id.value " . $subvols{$id}->{rfer} . "\n";
|
||
| 98 | } |
