Projet

Général

Profil

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

root / plugins / other / s3_storage @ c83e8840

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

1
#!/usr/bin/perl
2

    
3
use strict;
4

    
5

    
6
my $s3_id = exists $ENV{'s3_id'} ? $ENV{'s3_id'} : "user";    
7
my $s3cmd = 's3curl.pl --id  ' . $s3_id . '  http://s3.amazonaws.com/';
8

    
9

    
10

    
11
if ( $ARGV[0] eq "autoconf" ) {
12
    if (`/usr/bin/perl $0` eq "" ) {
13
    print "no\n";
14
    exit 1;
15
    } else {
16
    print "yes\n";
17
    exit 0;
18
    }
19
}
20

    
21

    
22

    
23
sub get_bucket_list() {
24

    
25

    
26
    my $buckets = `$s3cmd`;
27

    
28
    my $str = $buckets;
29

    
30
    my @bucket_list = ();
31
    my $pos = 0;
32
    
33
    while ($str =~ /.<Name>([\w._-]+)<\/Name>/) {
34

    
35
        $bucket_list[$pos++] = $1;
36
        $str = $';
37
    } 
38

    
39
    return @bucket_list; 
40
}
41

    
42

    
43
sub get_bucket_stats {
44
my ($name) = @_;
45

    
46
    my $s3cmd_local = $s3cmd . $name;
47
    my $stats = `$s3cmd_local`;
48

    
49
    my %res;
50
    
51
    $res{'size'}  = 0;        
52
    $res{'count'} = 0;        
53
        
54
    while ($stats =~ /.<Size>([\w._-]+)<\/Size>/) {
55
        $stats = $';
56
        
57
        $res{'size'} += $1;
58
        $res{'count'}++;
59
    } 
60
    return %res;
61
}
62

    
63

    
64

    
65
if ( $ARGV[0] eq "config" ) {
66

    
67
    # The headers
68
    print "graph_title S3 Storage Usage\n";
69
    print "graph_category s3\n";
70
    print "graph_args --base 1024 -l 0\n";
71
    print "graph_vlabel bytes\n";
72
    print 'graph_info Plugin available at <a href="http://www.ohardt.com/dev/munin/">http://www.ohardt.com/dev/munin/</a>' . "\n";
73
    
74
    my @bucket_list = get_bucket_list();
75
    
76
    my $bucket_name;
77
    
78
    foreach $bucket_name ( @bucket_list ) {
79
 
80
        print $bucket_name . ".label Bucket " . $bucket_name . "\n";   
81
    
82
    } 
83

    
84
    exit;
85
    
86
    
87
}
88

    
89

    
90
my @bucket_list = get_bucket_list();
91

    
92
my $bucket_name;
93
    
94
foreach $bucket_name ( @bucket_list ) {
95
 
96
    my %stats = get_bucket_stats( $bucket_name );   
97
 
98
    print $bucket_name . ".value " . $stats{'size'} . "\n";
99
}
100