Last active
December 11, 2015 19:19
-
-
Save mikeda/4647624 to your computer and use it in GitHub Desktop.
Cassandra監視用のmuninプラグインその1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
my $command = 'nodetool -h localhost tpstats'; | |
my $prefix = "cassandra_task_"; | |
my @graphs = qw(active pending completed); | |
my %configs = ( | |
active => { | |
tpstats_pos => 0, | |
graph_title => 'Cassandra Active Tasks', | |
graph_vlabel => 'tasks', | |
type => 'GAUGE' | |
}, | |
pending => { | |
tpstats_pos => 1, | |
graph_title => 'Cassandra Pending Tasks', | |
graph_vlabel => 'tasks', | |
type => 'GAUGE' | |
}, | |
completed => { | |
tpstats_pos => 2, | |
graph_title => 'Cassandra Completed Tasks', | |
graph_vlabel => 'tasks/sec', | |
type => 'COUNTER' | |
} | |
); | |
my @pool_names = qw( | |
ReadStage | |
RequestResponseStage | |
MutationStage | |
ReadRepairStage | |
ReplicateOnWriteStage | |
GossipStage | |
AntiEntropyStage | |
MigrationStage | |
MemtablePostFlusher | |
FlushWriter | |
MiscStage | |
InternalResponseStage | |
HintedHandoff | |
); | |
my $arg = shift; | |
if ($arg && $arg eq 'config') { | |
print_config(); | |
exit; | |
} elsif ($arg) { | |
exit; | |
} | |
open my $fh, '-|', $command | |
or die("Could not execute '$command': $!"); | |
my %results; | |
while(<$fh>){ | |
chomp; | |
my ($key, @values) = split; | |
next unless $key && grep {$_ eq $key} @pool_names; | |
while(my ($type, $config) = each(%configs)){ | |
$results{$type} ||= {}; | |
$results{$type}->{$key} = $values[$config->{tpstats_pos}]; | |
} | |
} | |
while(my ($type, $result) = each(%results)){ | |
print "multigraph $prefix$type\n"; | |
while(my ($key, $value) = each(%$result)){ | |
print "$key.value $value\n"; | |
} | |
print "\n"; | |
} | |
exit; | |
sub print_config { | |
while(my ($type, $config) = each(%configs)){ | |
my $num = 0; | |
print("multigraph $prefix$type\n", | |
"graph_title $config->{graph_title}\n", | |
"graph_args --base 1000\n", | |
"graph_vlabel $config->{graph_vlabel}\n", | |
"graph_category cassandra\n", | |
"graph_total total\n", | |
); | |
for my $title (@pool_names) { | |
print("$title.label ${title}\n", | |
"$title.min 0\n", | |
"$title.type $config->{type}\n", | |
"$title.max 500000\n", | |
"$title.draw ", ($num) ? "STACK" : "AREA" , "\n", | |
); | |
$num++; | |
} | |
print "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment