1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 10:39:53 +00:00

Added elasticsearch_* plugins (also compatible with opensearch)

This commit is contained in:
Rowan Wookey 2024-08-24 12:18:27 +01:00
parent bf9a4e4605
commit 4663c7cae6
12 changed files with 1296 additions and 0 deletions

View file

@ -0,0 +1,114 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_cache - A munin plugin that collects cache stats of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Tomas Doran (t0m) - c<< <bobtfish@bobtfish.net> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes");
my $t_data = get_json_from_url("/_nodes/stats");
my %out = ( fielddata_size => 0, query_cache_size => 0, request_cache_size => 0 );
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $t_data->{nodes}{$full_node_name};
if ( defined( $t_data->{nodes}{$full_node_name}{indices}{fielddata} ) ) {
$out{fielddata_size}
+= $t_data->{nodes}{$full_node_name}{indices}{fielddata}{memory_size_in_bytes};
}
if ( defined( $t_data->{nodes}{$full_node_name}{indices}{query_cache} ) ) {
$out{query_cache_size}
+= $t_data->{nodes}{$full_node_name}{indices}{query_cache}{memory_size_in_bytes};
}
if ( defined( $t_data->{nodes}{$full_node_name}{indices}{request_cache} ) ) {
$out{request_cache_size}
+= $t_data->{nodes}{$full_node_name}{indices}{request_cache}{memory_size_in_bytes};
}
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_args --base 1024\n";
print "graph_title elasticsearch cache\n";
print "graph_category elasticsearch\n";
print "graph_vlabel Bytes\n";
foreach my $name ( keys %out ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,108 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_cluster_health - A munin plugin that collects health stats of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_cluster/health");
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title elasticsearch cluster health\n";
print "graph_category elasticsearch\n";
print "graph_scale no\n";
print "green.label green\n" . "green.type GAUGE\n" . "green.draw AREA\n";
print "yellow.label yellow\n" . "yellow.type GAUGE\n" . "yellow.draw AREA\n";
print "red.label red\n" . "red.type GAUGE\n" . "red.draw AREA\n";
}
else {
if ( $data->{status} eq "green" ) {
print "green.value 1\n";
}
else {
print "green.value 0\n";
}
if ( $data->{status} eq "yellow" ) {
print "yellow.value 1\n";
}
else {
print "yellow.value 0\n";
}
if ( $data->{status} eq "red" ) {
print "red.value 1\n";
}
else {
print "red.value 0\n";
}
}

View file

@ -0,0 +1,94 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_cluster_nodes - A munin plugin that collects node stats of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_cluster/health");
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title elasticsearch cluster nodes\n";
print "graph_category elasticsearch\n";
print "graph_scale no\n";
foreach my $name ( grep { /_nodes$/ } keys %$data ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( grep { /_nodes$/ } keys %$data ) {
print "$name.value " . $data->{$name} . "\n";
}
}

View file

@ -0,0 +1,96 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_cluster_shards - A munin plugin that collects shard stats of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Tomas Doran (t0m) - c<< <bobtfish@bobtfish.net> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_cluster/health");
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title elasticsearch cluster shards\n";
print "graph_category elasticsearch\n";
print "graph_scale no\n";
foreach my $name ( grep { /_shards$/ } keys %$data ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( grep { /_shards$/ } keys %$data ) {
print "$name.value " . $data->{$name} . "\n";
}
}

View file

@ -0,0 +1,103 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_docs - A munin plugin that collects document stats of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Tomas Doran (t0m) - c<< <bobtfish@bobtfish.net> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes");
my $t_data = get_json_from_url("/_nodes/stats");
my %out = ( num_docs => 0, deleted_docs => 0 );
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $t_data->{nodes}{$full_node_name};
$out{num_docs} += $t_data->{nodes}{$full_node_name}{indices}{docs}{count};
$out{deleted_docs} += $t_data->{nodes}{$full_node_name}{indices}{docs}{deleted};
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title elasticsearch documents\n";
print "graph_category elasticsearch\n";
foreach my $name ( keys %out ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,108 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_gc_time - A munin plugin that collects garbage collection time stats of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Timothy Messier (t0m) - c<< <tim.messier@gmail.com> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes/_local/stats/jvm");
my %out = ( young => 0, old => 0 );
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $data->{nodes}{$full_node_name};
if ( defined( $data->{nodes}{$full_node_name}{jvm}{gc}{collectors}{young} ) ) {
$out{young}
+= $data->{nodes}{$full_node_name}{jvm}{gc}{collectors}{young}{collection_time_in_millis};
}
if ( defined( $data->{nodes}{$full_node_name}{jvm}{gc}{collectors}{old} ) ) {
$out{old}
+= $data->{nodes}{$full_node_name}{jvm}{gc}{collectors}{old}{collection_time_in_millis};
}
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title Elasticsearch gc time\n";
print "graph_category elasticsearch\n";
print "graph_vlabel miliseconds\n";
foreach my $name ( keys %out ) {
print "$name.label $name\n" . "$name.type COUNTER\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,108 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_index_size - A munin plugin that collects index size of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Tomas Doran (t0m) - c<< <bobtfish@bobtfish.net> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes");
my $t_data = get_json_from_url("/_nodes/stats");
my %out = ( index_size => 0, total_data_set_size => 0, reserved_size => 0 );
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $t_data->{nodes}{$full_node_name};
$out{index_size} += $t_data->{nodes}{$full_node_name}{indices}{store}{size_in_bytes};
if ( exists $t_data->{nodes}{$full_node_name}{indices}{store}{total_data_set_size_in_bytes} ) {
$out{total_data_set_size}
+= $t_data->{nodes}{$full_node_name}{indices}{store}{total_data_set_size_in_bytes};
}
$out{reserved_size} += $t_data->{nodes}{$full_node_name}{indices}{store}{reserved_in_bytes};
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_args --base 1024\n";
print "graph_title Elasticsearch indexes\n";
print "graph_category elasticsearch\n";
print "graph_vlabel Bytes\n";
foreach my $name ( keys %out ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,112 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_index_total - A munin plugin that collects stats about the index totals
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes");
my $t_data = get_json_from_url("/_nodes/stats");
my %out;
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $t_data->{nodes}{$full_node_name};
$out{index} += $t_data->{nodes}{$full_node_name}{indices}{indexing}{index_total};
$out{get} += $t_data->{nodes}{$full_node_name}{indices}{get}{total};
$out{missing} += $t_data->{nodes}{$full_node_name}{indices}{get}{missing_total};
$out{exists} += $t_data->{nodes}{$full_node_name}{indices}{get}{exists_total};
$out{search} += $t_data->{nodes}{$full_node_name}{indices}{search}{query_total};
$out{delete} += $t_data->{nodes}{$full_node_name}{indices}{indexing}{delete_total};
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title Elasticsearch index operations\n";
print "graph_category elasticsearch\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel Operations per second\n";
print "graph_order index get missing exists search delete\n";
for my $name ( keys %out ) {
print "$name.label $name\n";
print "$name.type DERIVE\n";
print "$name.min 0\n";
print "$name.draw LINE2\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,111 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_jvm_memory - A munin plugin that collects JVM memory stats from the JVM of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Tomas Doran (t0m) - c<< <bobtfish@bobtfish.net> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes/_local/stats/jvm");
my %out = (
heap_max => 0,
heap_committed => 0,
heap_used => 0,
non_heap_committed => 0,
non_heap_used => 0
);
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $data->{nodes}{$full_node_name};
foreach my $name ( grep { /_in_bytes$/ } keys %{ $data->{nodes}{$full_node_name}{jvm}{mem} } ) {
my ($dname) = $name =~ m/(.+)_in_bytes$/;
$out{$dname} += $data->{nodes}{$full_node_name}{jvm}{mem}{$name};
}
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_args --base 1024\n";
print "graph_title Elasticsearch JVM memory usage\n";
print "graph_category elasticsearch\n";
print "graph_vlabel Bytes\n";
foreach my $name ( keys %out ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,125 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_jvm_pools_size - A munin plugin that collects jvm pools size stats of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Timothy Messier (t0m) - c<< <tim.messier@gmail.com> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes/jvm");
my $t_data = get_json_from_url("/_nodes/stats/jvm");
my %out = (
young_used => 0,
young_peak => 0,
survivor_used => 0,
survivor_peak => 0,
old_used => 0,
old_peak => 0
);
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $t_data->{nodes}{$full_node_name};
if ( defined( $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{young} ) ) {
$out{young_used}
+= $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{young}{used_in_bytes};
$out{young_peak}
+= $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{young}{peak_used_in_bytes};
}
if ( defined( $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{survivor} ) ) {
$out{survivor_used}
+= $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{survivor}{used_in_bytes};
$out{survivor_peak}
+= $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{survivor}{peak_used_in_bytes};
}
if ( defined( $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{old} ) ) {
$out{old_used} += $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{old}{used_in_bytes};
$out{old_peak}
+= $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{old}{peak_used_in_bytes};
}
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title Elasticsearch jvm pools size\n";
print "graph_category elasticsearch\n";
print "graph_vlabel bytes\n";
foreach my $name ( keys %out ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,104 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_jvm_threads - A munin plugin that collects stats from the JVM of your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Tomas Doran (t0m) - c<< <bobtfish@bobtfish.net> >>
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
my $data = get_json_from_url("/_nodes/jvm");
my $t_data = get_json_from_url("/_nodes/stats/jvm");
my %out = ( count => 0, peak_count => 0 );
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
next unless $t_data->{nodes}{$full_node_name};
foreach my $name ( keys %{ $t_data->{nodes}{$full_node_name}{jvm}{threads} } ) {
$out{$name} += $t_data->{nodes}{$full_node_name}{jvm}{threads}{$name};
}
}
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title Elasticsearch JVM threads\n";
print "graph_category elasticsearch\n";
print "graph_scale no\n";
foreach my $name ( keys %out ) {
print "$name.label $name\n" . "$name.type GAUGE\n";
}
}
else {
foreach my $name ( keys %out ) {
print "$name.value " . $out{$name} . "\n";
}
}

View file

@ -0,0 +1,113 @@
#!/usr/bin/env perl
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use LWP;
use JSON qw/decode_json/;
=head1 NAME
elasticsearch_open_files - A munin plugin that collects the number of open files in your elasticsearch instances
=head1 APPLICABLE SYSTEMS
Elasticsearch
=head1 CONFIGURATION
None
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Kentaro Yoshida - https://github.com/y-ken
Rowan Wookey - https://www.rwky.net
=head1 LICENSE
MIT
=cut
my $url = exists $ENV{'url'} ? $ENV{'url'} : 'http://localhost:9200';
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
sub autoconf {
my $res = $ua->get( $url, 'Content-Type' => 'application/json' );
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
if ( $data->{version}->{number} ) {
print("yes\n");
}
else {
print("no\n");
}
exit(0);
}
if ( $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
autoconf();
}
sub get_json_from_url {
my $uri = shift;
my $res = $ua->get( $url . $uri, 'Content-Type' => 'application/json' );
Carp::confess( $res->code . " for " . $uri ) unless $res->is_success;
my $data = do {
local $@;
eval { decode_json( $res->content ) }
};
die( "Could not decode JSON from: " . $res->content ) unless $data;
return $data;
}
sub collect_max_file_descriptors {
my $data = get_json_from_url("/_nodes/_local/stats/process");
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
return $data->{nodes}{$full_node_name}{process}{max_file_descriptors};
}
}
sub collect_open_file_descriptors {
my $data = get_json_from_url("/_nodes/_local/stats/process");
foreach my $full_node_name ( keys %{ $data->{nodes} } ) {
return $data->{nodes}{$full_node_name}{process}{open_file_descriptors};
}
}
my %out = (
max_file_descriptors => collect_max_file_descriptors,
open_file_descriptors => collect_open_file_descriptors
);
if ( $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title Elasticsearch open files\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel number of open files\n";
print "graph_category elasticsearch\n";
print "open_file_descriptors.label open files\n";
print "open_file_descriptors.type GAUGE\n";
print "open_file_descriptors.info The number of currently open files.\n";
print "max_file_descriptors.label max open files\n";
print "max_file_descriptors.type GAUGE\n";
}
else {
print "max_file_descriptors.value $out{max_file_descriptors}\n";
print "open_file_descriptors.value $out{open_file_descriptors}\n";
}