Skip to content

Instantly share code, notes, and snippets.

@jayjanssen
Last active December 31, 2015 06:09
Show Gist options
  • Save jayjanssen/7945311 to your computer and use it in GitHub Desktop.
Save jayjanssen/7945311 to your computer and use it in GitHub Desktop.
Munin plugin for Bitcasa Linux client
#!/usr/bin/perl
my $stats = "/var/lib/bitcasa/stats";
my %patterns = (
'max_cache' => qr/Maximum Cache Size Setting: (.*)$/,
'current_cache' => qr/Current Cache Size: (.*)$/,
'available_cache' => qr/Available Cache Space: (.*)$/,
'used_cache' => qr/Used Cache Space: (.*)$/,
'pending_upload' => qr/Bytes Queued for Upload: (.*)$/,
);
my %units = (
'TB' => 1024 * 1024 * 1024 * 1024,
'GB' => 1024 * 1024 * 1024,
'MB' => 1024 * 1024,
'KB' => 1024,
);
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
if (-r $stats ) {
print "yes\n";
exit 0;
} else {
print "no ($stats not found)\n";
exit 0;
}
}
if( $ARGV[0] eq 'config' ) {
print <<END;
graph_args -l 0
graph_vlabel Bytes
graph_title Bitcasa
graph_category bitcasa
graph_info This graph shows Bitcasa local cache usage
graph_order current_cache used_cache pending_upload
current_cache.label Cache size
current_cache.draw AREA
current_cache.info Current cache size
used_cache.label Used cache
used_cache.draw AREA
used_cache.info Cache in use
pending_upload.label Pending upload
pending_upload.draw LINE2
pending_upload.info Data pending upload
END
exit;
}
# Convert "\d+[.\d+] XB" to Bytes
sub convert_units {
my( $raw_number ) = @_;
if( $raw_number =~ m/(?<number>\d+(\.\d+)?)\s(?<units>\S\S)/ ) {
return $+{number} * $units{$+{units}};
} else {
die "Could not convert $raw_number\n";
}
}
open( STATS, "< $stats" ) or die "Could not open bitcasa stats: $stats\n";
my %stats;
while( my $line = <STATS> ) {
foreach my $key( keys %patterns ) {
my $pattern = $patterns{$key};
if( $line =~ $pattern ) {
$stats{$key} = &convert_units( $1 );
}
}
}
close( STATS );
foreach my $key( keys %stats ) {
print "$key.value $stats{$key}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment