Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / s3 / s3_storage @ 17f78427

Historique | Voir | Annoter | Télécharger (1,65 ko)

1
#!/usr/bin/perl
2

    
3
use strict;
4
use warnings;
5

    
6
my $s3_id = exists $ENV{'s3_id'} ? $ENV{'s3_id'} : "user";
7
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

    
15
    while ($buckets =~ s/.<Name>([\w._-]+)<\/Name>//)
16
	 {
17
        push @bucket_list, $1;
18
    }
19

    
20
    return @bucket_list;
21
}
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

    
49
    $res{'size'}  = 0;
50

    
51
    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
    print "graph_category cloud\n";
65
    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

    
69
    foreach my $bucket_name (@bucket_list)
70
	 {
71
        print "$bucket_name.label Bucket $bucket_name\n";
72
    }
73

    
74
    exit;
75
}
76

    
77
foreach my $bucket_name (@bucket_list)
78
{
79
    my %stats = get_bucket_stats($bucket_name);
80
    print "$bucket_name.value " . $stats{'size'} . "\n";
81
}
82

    
83
exit 0;