mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 10:39:53 +00:00
125 lines
3.1 KiB
Perl
Executable file
125 lines
3.1 KiB
Perl
Executable file
#!/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";
|
|
}
|
|
}
|