2009-02-01 21:16:57 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
my $s3_id = exists $ENV{'s3_id'} ? $ENV{'s3_id'} : "user";
|
2009-02-01 21:16:57 +01:00
|
|
|
my $s3cmd = 's3curl.pl --id ' . $s3_id . ' http://s3.amazonaws.com/';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( $ARGV[0] eq "autoconf" ) {
|
|
|
|
if (`/usr/bin/perl $0` eq "" ) {
|
2018-09-16 04:01:57 +02:00
|
|
|
print "no\n";
|
2009-02-01 21:16:57 +01:00
|
|
|
} else {
|
2018-09-16 04:01:57 +02:00
|
|
|
print "yes\n";
|
2009-02-01 21:16:57 +01:00
|
|
|
}
|
2018-09-16 04:01:57 +02:00
|
|
|
exit 0;
|
2009-02-01 21:16:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub get_bucket_list() {
|
|
|
|
|
|
|
|
|
|
|
|
my $buckets = `$s3cmd`;
|
|
|
|
|
|
|
|
my $str = $buckets;
|
|
|
|
|
|
|
|
my @bucket_list = ();
|
|
|
|
my $pos = 0;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
while ($str =~ /.<Name>([\w._-]+)<\/Name>/) {
|
|
|
|
|
|
|
|
$bucket_list[$pos++] = $1;
|
|
|
|
$str = $';
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2009-02-01 21:16:57 +01:00
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
return @bucket_list;
|
2009-02-01 21:16:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub get_bucket_stats {
|
|
|
|
my ($name) = @_;
|
|
|
|
|
|
|
|
my $s3cmd_local = $s3cmd . $name;
|
|
|
|
my $stats = `$s3cmd_local`;
|
|
|
|
|
|
|
|
my %res;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
|
|
$res{'size'} = 0;
|
|
|
|
$res{'count'} = 0;
|
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
while ($stats =~ /.<Size>([\w._-]+)<\/Size>/) {
|
|
|
|
$stats = $';
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
$res{'size'} += $1;
|
|
|
|
$res{'count'}++;
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2009-02-01 21:16:57 +01:00
|
|
|
return %res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( $ARGV[0] eq "config" ) {
|
|
|
|
|
|
|
|
# The headers
|
|
|
|
print "graph_title S3 Items\n";
|
2017-02-20 22:14:23 +01:00
|
|
|
print "graph_category cloud\n";
|
2009-02-01 21:16:57 +01:00
|
|
|
print "graph_vlabel items\n";
|
|
|
|
print 'graph_info Plugin available at <a href="http://www.ohardt.com/dev/munin/">http://www.ohardt.com/dev/munin/</a>' . "\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
my @bucket_list = get_bucket_list();
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
my $bucket_name;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
foreach $bucket_name ( @bucket_list ) {
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
|
|
print $bucket_name . ".label Bucket " . $bucket_name . "\n";
|
|
|
|
|
|
|
|
}
|
2009-02-01 21:16:57 +01:00
|
|
|
|
|
|
|
exit;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my @bucket_list = get_bucket_list();
|
|
|
|
|
|
|
|
my $bucket_name;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
foreach $bucket_name ( @bucket_list ) {
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
|
|
my %stats = get_bucket_stats( $bucket_name );
|
|
|
|
|
2009-02-01 21:16:57 +01:00
|
|
|
print $bucket_name . ".value " . $stats{'count'} . "\n";
|
|
|
|
}
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|