mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Initial version
This commit is contained in:
parent
9ab40d7eaf
commit
c83e884024
100
plugins/other/s3_storage
Executable file
100
plugins/other/s3_storage
Executable file
@ -0,0 +1,100 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
|
||||
|
||||
my $s3_id = exists $ENV{'s3_id'} ? $ENV{'s3_id'} : "user";
|
||||
my $s3cmd = 's3curl.pl --id ' . $s3_id . ' http://s3.amazonaws.com/';
|
||||
|
||||
|
||||
|
||||
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`;
|
||||
|
||||
my $str = $buckets;
|
||||
|
||||
my @bucket_list = ();
|
||||
my $pos = 0;
|
||||
|
||||
while ($str =~ /.<Name>([\w._-]+)<\/Name>/) {
|
||||
|
||||
$bucket_list[$pos++] = $1;
|
||||
$str = $';
|
||||
}
|
||||
|
||||
return @bucket_list;
|
||||
}
|
||||
|
||||
|
||||
sub get_bucket_stats {
|
||||
my ($name) = @_;
|
||||
|
||||
my $s3cmd_local = $s3cmd . $name;
|
||||
my $stats = `$s3cmd_local`;
|
||||
|
||||
my %res;
|
||||
|
||||
$res{'size'} = 0;
|
||||
$res{'count'} = 0;
|
||||
|
||||
while ($stats =~ /.<Size>([\w._-]+)<\/Size>/) {
|
||||
$stats = $';
|
||||
|
||||
$res{'size'} += $1;
|
||||
$res{'count'}++;
|
||||
}
|
||||
return %res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( $ARGV[0] eq "config" ) {
|
||||
|
||||
# The headers
|
||||
print "graph_title S3 Storage Usage\n";
|
||||
print "graph_category s3\n";
|
||||
print "graph_args --base 1024 -l 0\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";
|
||||
|
||||
my @bucket_list = get_bucket_list();
|
||||
|
||||
my $bucket_name;
|
||||
|
||||
foreach $bucket_name ( @bucket_list ) {
|
||||
|
||||
print $bucket_name . ".label Bucket " . $bucket_name . "\n";
|
||||
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
my @bucket_list = get_bucket_list();
|
||||
|
||||
my $bucket_name;
|
||||
|
||||
foreach $bucket_name ( @bucket_list ) {
|
||||
|
||||
my %stats = get_bucket_stats( $bucket_name );
|
||||
|
||||
print $bucket_name . ".value " . $stats{'size'} . "\n";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user