root / plugins / quota-usage @ 8f2bcef9
Historique | Voir | Annoter | Télécharger (2,47 ko)
| 1 |
#!/usr/bin/perl -W |
|---|---|
| 2 |
# |
| 3 |
# [ML] SOURCE: http://munin.projects.linpro.no/attachment/ticket/143/quota-usage |
| 4 |
# |
| 5 |
# Plugin to monitor quota on a specified device. Needs repquota and root privs |
| 6 |
# |
| 7 |
# Usage: place in /etc/munin/node.d/quota-usage_<dev> (or link it there using |
| 8 |
# ln -s), for example quota-usage_hda3. Use underscores instead of slashes, for |
| 9 |
# example to monitor /dev/mapper/vol-foo, name this quota-usage_mapper_vol-foo |
| 10 |
# |
| 11 |
# This plugin uses the soft and hard quota data for warning and critical levels |
| 12 |
# respectively. |
| 13 |
# |
| 14 |
# Parameters understood: |
| 15 |
# |
| 16 |
# config (required) |
| 17 |
# |
| 18 |
#%# family=manual |
| 19 |
# |
| 20 |
use strict; |
| 21 |
use warnings; |
| 22 |
|
| 23 |
# We do some magic to allow device strings with underscore to mean a / |
| 24 |
# So to monitor /dev/mapper/vol-foo use quota-usage_mapper_vol-foo |
| 25 |
my @tmp = split(/_/, $0); |
| 26 |
shift @tmp; |
| 27 |
my $dev = join("/", @tmp);
|
| 28 |
my %users; |
| 29 |
|
| 30 |
open (REP, "/usr/sbin/repquota /dev/$dev |") or exit 22; |
| 31 |
while (<REP>) {
|
| 32 |
chomp; |
| 33 |
if (/^-+$/../^$/) {
|
| 34 |
my @data = split(/ +/); |
| 35 |
if ( @data > 2 && $data[2] > 0 ) {
|
| 36 |
$users{$data[0]}[0] = $data[2]; # current usage
|
| 37 |
$users{$data[0]}[1] = $data[3]; # Soft quota
|
| 38 |
$users{$data[0]}[2] = $data[4]; # Hard quota
|
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
close REP; |
| 43 |
|
| 44 |
|
| 45 |
my @sorted_users; |
| 46 |
@sorted_users = sort keys %users; # sorted by username |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
my $user; |
| 51 |
my @value; |
| 52 |
|
| 53 |
if ($ARGV[0] and $ARGV[0] eq "config") {
|
| 54 |
print "graph_title Filesystem usage by user (quota based) on $dev\n"; |
| 55 |
print "graph_args --base 1024 --lower-limit 0\n"; |
| 56 |
print "graph_vlabel bytes\n"; |
| 57 |
print "graph_category disk\n"; |
| 58 |
|
| 59 |
foreach (@sorted_users) {
|
| 60 |
my $user = $_; |
| 61 |
my ($uid, $name) = (getpwnam($user))[2,6]; |
| 62 |
my $esc = $user; |
| 63 |
$esc =~ s/-/_/g; |
| 64 |
$name = (split(/,/, $name))[0]; |
| 65 |
printf "%s.label %s\n", $esc, $name; |
| 66 |
if ( $users{$user}[1] > 0 ) {
|
| 67 |
printf "%s.warning %s\n", $esc, $users{$user}[1];
|
| 68 |
} |
| 69 |
if ( $users{$user}[2] > 0 ) {
|
| 70 |
printf "%s.critical %s\n", $esc, $users{$user}[2];
|
| 71 |
} |
| 72 |
printf "%s.cdef %s,1024,*\n", $esc, $esc; |
| 73 |
if (($uid < 500)) {
|
| 74 |
printf "%s.graph no\n", $esc; |
| 75 |
} |
| 76 |
} |
| 77 |
} else {
|
| 78 |
foreach (@sorted_users) {
|
| 79 |
my $user = $_; |
| 80 |
my $esc = $user; |
| 81 |
$esc =~ s/-/_/g; |
| 82 |
printf "%s.value %s\n", $esc, $users{$user}[0];
|
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
# vim: set ts=4 sw=4: |
