root / plugins / s3 / s3_storage @ 17f78427
Historique | Voir | Annoter | Télécharger (1,65 ko)
| 1 | db184710 | Chris Wilson | #!/usr/bin/perl |
|---|---|---|---|
| 2 | |||
| 3 | use strict; |
||
| 4 | use warnings; |
||
| 5 | |||
| 6 | 17f78427 | Lars Kruse | my $s3_id = exists $ENV{'s3_id'} ? $ENV{'s3_id'} : "user";
|
| 7 | db184710 | Chris Wilson | my $s3curl = "perl s3-curl/s3curl.pl --id $s3_id -- -s -S"; |
| 8 | |||
| 9 | sub get_bucket_list() |
||
| 10 | {
|
||
| 11 | my $buckets = `$s3curl http://s3.amazonaws.com`; |
||
| 12 | my $str = $buckets; |
||
| 13 | my @bucket_list; |
||
| 14 | 17f78427 | Lars Kruse | |
| 15 | db184710 | Chris Wilson | while ($buckets =~ s/.<Name>([\w._-]+)<\/Name>//) |
| 16 | {
|
||
| 17 | push @bucket_list, $1; |
||
| 18 | 17f78427 | Lars Kruse | } |
| 19 | db184710 | Chris Wilson | |
| 20 | 17f78427 | Lars Kruse | return @bucket_list; |
| 21 | db184710 | Chris Wilson | } |
| 22 | |||
| 23 | my @bucket_list = split /\s+/, ($ENV{'buckets'} || '');
|
||
| 24 | if (not @bucket_list) |
||
| 25 | {
|
||
| 26 | @bucket_list = get_bucket_list(); |
||
| 27 | } |
||
| 28 | |||
| 29 | if ($ARGV[0] and $ARGV[0] eq "autoconf") |
||
| 30 | {
|
||
| 31 | if (@bucket_list) |
||
| 32 | {
|
||
| 33 | print "yes\n"; |
||
| 34 | exit 0; |
||
| 35 | } |
||
| 36 | else |
||
| 37 | {
|
||
| 38 | print "no\n"; |
||
| 39 | exit 1; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | sub get_bucket_stats |
||
| 44 | {
|
||
| 45 | my ($name) = @_; |
||
| 46 | my $stats = `$s3curl http://$name.s3.amazonaws.com`; |
||
| 47 | my %res; |
||
| 48 | 17f78427 | Lars Kruse | |
| 49 | db184710 | Chris Wilson | $res{'size'} = 0;
|
| 50 | 17f78427 | Lars Kruse | |
| 51 | db184710 | Chris Wilson | while ($stats =~ s/.<Size>([\w._-]+)<\/Size>//) |
| 52 | {
|
||
| 53 | $res{'size'} += $1;
|
||
| 54 | $res{'count'}++;
|
||
| 55 | } |
||
| 56 | |||
| 57 | return %res; |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($ARGV[0] and $ARGV[0] eq "config") |
||
| 61 | {
|
||
| 62 | # The headers |
||
| 63 | print "graph_title S3 Storage Usage\n"; |
||
| 64 | e00b066f | dipohl | print "graph_category cloud\n"; |
| 65 | db184710 | Chris Wilson | print "graph_args --base 1024 -l 0\n"; |
| 66 | print "graph_vlabel bytes\n"; |
||
| 67 | 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"; |
||
| 68 | 17f78427 | Lars Kruse | |
| 69 | db184710 | Chris Wilson | foreach my $bucket_name (@bucket_list) |
| 70 | {
|
||
| 71 | print "$bucket_name.label Bucket $bucket_name\n"; |
||
| 72 | 17f78427 | Lars Kruse | } |
| 73 | db184710 | Chris Wilson | |
| 74 | exit; |
||
| 75 | } |
||
| 76 | |||
| 77 | foreach my $bucket_name (@bucket_list) |
||
| 78 | {
|
||
| 79 | 17f78427 | Lars Kruse | my %stats = get_bucket_stats($bucket_name); |
| 80 | db184710 | Chris Wilson | print "$bucket_name.value " . $stats{'size'} . "\n";
|
| 81 | } |
||
| 82 | |||
| 83 | exit 0; |
