mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
Fix line endings to Unix.
Standardise indentation, spacing and braces. Allow overriding the list of buckets, default to all buckets. Hide a lot of unwanted output from Curl.
This commit is contained in:
parent
73239ed265
commit
db184710e5
1 changed files with 83 additions and 100 deletions
|
@ -1,100 +1,83 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
my $s3_id = exists $ENV{'s3_id'} ? $ENV{'s3_id'} : "user";
|
my $s3_id = exists $ENV{'s3_id'} ? $ENV{'s3_id'} : "user";
|
||||||
my $s3cmd = 's3curl.pl --id ' . $s3_id . ' http://s3.amazonaws.com/';
|
my $s3curl = "perl s3-curl/s3curl.pl --id $s3_id -- -s -S";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( $ARGV[0] eq "autoconf" ) {
|
|
||||||
if (`/usr/bin/perl $0` eq "" ) {
|
|
||||||
print "no\n";
|
|
||||||
exit 1;
|
|
||||||
} else {
|
|
||||||
print "yes\n";
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub get_bucket_list() {
|
|
||||||
|
|
||||||
|
|
||||||
my $buckets = `$s3cmd`;
|
|
||||||
|
|
||||||
|
sub get_bucket_list()
|
||||||
|
{
|
||||||
|
my $buckets = `$s3curl http://s3.amazonaws.com`;
|
||||||
my $str = $buckets;
|
my $str = $buckets;
|
||||||
|
my @bucket_list;
|
||||||
|
|
||||||
my @bucket_list = ();
|
while ($buckets =~ s/.<Name>([\w._-]+)<\/Name>//)
|
||||||
my $pos = 0;
|
{
|
||||||
|
push @bucket_list, $1;
|
||||||
while ($str =~ /.<Name>([\w._-]+)<\/Name>/) {
|
|
||||||
|
|
||||||
$bucket_list[$pos++] = $1;
|
|
||||||
$str = $';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return @bucket_list;
|
return @bucket_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my @bucket_list = split /\s+/, ($ENV{'buckets'} || '');
|
||||||
|
if (not @bucket_list)
|
||||||
|
{
|
||||||
|
@bucket_list = get_bucket_list();
|
||||||
|
}
|
||||||
|
|
||||||
sub get_bucket_stats {
|
if ($ARGV[0] and $ARGV[0] eq "autoconf")
|
||||||
my ($name) = @_;
|
{
|
||||||
|
if (@bucket_list)
|
||||||
my $s3cmd_local = $s3cmd . $name;
|
{
|
||||||
my $stats = `$s3cmd_local`;
|
print "yes\n";
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "no\n";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_bucket_stats
|
||||||
|
{
|
||||||
|
my ($name) = @_;
|
||||||
|
my $stats = `$s3curl http://$name.s3.amazonaws.com`;
|
||||||
my %res;
|
my %res;
|
||||||
|
|
||||||
$res{'size'} = 0;
|
$res{'size'} = 0;
|
||||||
$res{'count'} = 0;
|
|
||||||
|
|
||||||
while ($stats =~ /.<Size>([\w._-]+)<\/Size>/) {
|
|
||||||
$stats = $';
|
|
||||||
|
|
||||||
|
while ($stats =~ s/.<Size>([\w._-]+)<\/Size>//)
|
||||||
|
{
|
||||||
$res{'size'} += $1;
|
$res{'size'} += $1;
|
||||||
$res{'count'}++;
|
$res{'count'}++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return %res;
|
return %res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($ARGV[0] and $ARGV[0] eq "config")
|
||||||
|
{
|
||||||
if ( $ARGV[0] eq "config" ) {
|
|
||||||
|
|
||||||
# The headers
|
# The headers
|
||||||
print "graph_title S3 Storage Usage\n";
|
print "graph_title S3 Storage Usage\n";
|
||||||
print "graph_category s3\n";
|
print "graph_category s3\n";
|
||||||
print "graph_args --base 1024 -l 0\n";
|
print "graph_args --base 1024 -l 0\n";
|
||||||
print "graph_vlabel bytes\n";
|
print "graph_vlabel bytes\n";
|
||||||
print 'graph_info Plugin available at <a href="http://www.ohardt.com/dev/munin/">http://www.ohardt.com/dev/munin/</a>' . "\n";
|
print "graph_info Plugin available at <a href='https://github.com/aptivate/munin-contrib/blob/master/plugins/s3/s3_storage'>https://github.com/aptivate/munin-contrib/blob/master/plugins/s3/s3_storage</a>\n";
|
||||||
|
|
||||||
my @bucket_list = get_bucket_list();
|
|
||||||
|
|
||||||
my $bucket_name;
|
|
||||||
|
|
||||||
foreach $bucket_name ( @bucket_list ) {
|
|
||||||
|
|
||||||
print $bucket_name . ".label Bucket " . $bucket_name . "\n";
|
|
||||||
|
|
||||||
|
foreach my $bucket_name (@bucket_list)
|
||||||
|
{
|
||||||
|
print "$bucket_name.label Bucket $bucket_name\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach my $bucket_name (@bucket_list)
|
||||||
my @bucket_list = get_bucket_list();
|
{
|
||||||
|
my %stats = get_bucket_stats($bucket_name);
|
||||||
my $bucket_name;
|
print "$bucket_name.value " . $stats{'size'} . "\n";
|
||||||
|
|
||||||
foreach $bucket_name ( @bucket_list ) {
|
|
||||||
|
|
||||||
my %stats = get_bucket_stats( $bucket_name );
|
|
||||||
|
|
||||||
print $bucket_name . ".value " . $stats{'size'} . "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue