Skip to content

Commit 0c15fee

Browse files
committed
Initial commit
1 parent a783698 commit 0c15fee

7 files changed

+499
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# munin-plugin-logstash
2-
munin plugin for logstash via monitor API
2+
munin plugin for Logstash via monitor API

logstash_gc_time

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env perl
2+
3+
# Parameters supported:
4+
#
5+
# config
6+
# autoconf
7+
#
8+
# Magic markers:
9+
#%# family=auto
10+
#%# capabilities=autoconf
11+
12+
use strict;
13+
use warnings;
14+
use LWP;
15+
use JSON qw/decode_json/;
16+
17+
=head1 NAME
18+
19+
logstash_gc_time - A munin plugin that collects garbage collection time stats of your Logstash instances
20+
21+
=head1 APPLICABLE SYSTEMS
22+
23+
Logstash
24+
25+
=head1 CONFIGURATION
26+
27+
[logstash_*]
28+
env.host 127.0.0.1
29+
env.port 9600
30+
31+
=head1 BUGS
32+
33+
None known so far. If you find any, let me know.
34+
35+
=head1 AUTHOR
36+
37+
Original Author:
38+
Timothy Messier (t0m) - c<< <[email protected]> >>
39+
Kentaro Yoshida - https://github.com/y-ken
40+
41+
Modified by Hirokazu MORIKAWA <[email protected]>
42+
43+
=cut
44+
45+
my $host = exists $ENV{'host'} ? $ENV{'host'} : 'localhost';
46+
my $port = exists $ENV{'port'} ? $ENV{'port'} : 9600;
47+
48+
my $ua = LWP::UserAgent->new;
49+
$ua->timeout(10);
50+
51+
sub get_json_from_url {
52+
my $uri = shift;
53+
my $res = $ua->get($uri, 'Content-Type' => 'application/json' );
54+
Carp::confess($res->code . " for " . $uri) unless $res->is_success;
55+
my $data = do { local $@; eval { decode_json($res->content) } };
56+
die("Could not decode JSON from: " . $res->content) unless $data;
57+
return $data;
58+
}
59+
60+
my $data = get_json_from_url("http://$host:$port/_node/stats/jvm");
61+
my %out = (young => 0, old => 0);
62+
63+
$out{young} = $data->{jvm}{gc}{collectors}{young}{collection_time_in_millis};
64+
$out{old} = $data->{jvm}{gc}{collectors}{old}{collection_time_in_millis};
65+
66+
if ($ARGV[0] and $ARGV[0] eq 'config') {
67+
print "graph_title Logstash (port $port) GC time\n";
68+
print "graph_category logstash\n";
69+
print "graph_vlabel miliseconds\n";
70+
71+
foreach my $name (keys %out) {
72+
print "$name.label $name\n"."$name.type COUNTER\n";
73+
}
74+
}
75+
elsif (!$ARGV[0] || $ARGV[0] eq 'autoconf') {
76+
foreach my $name (keys %out) {
77+
print "$name.value " . $out{$name} . "\n";
78+
}
79+
}
80+
81+
exit(0);

logstash_jvm_memory

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env perl
2+
3+
# Parameters supported:
4+
#
5+
# config
6+
# autoconf
7+
#
8+
# Magic markers:
9+
#%# family=auto
10+
#%# capabilities=autoconf
11+
12+
use strict;
13+
use warnings;
14+
use LWP;
15+
use JSON qw/decode_json/;
16+
17+
=head1 NAME
18+
19+
logstash_jvm_memory - A munin plugin that collects JVM memory stats from the JVM of your Logstash instances
20+
21+
=head1 APPLICABLE SYSTEMS
22+
23+
Logstash
24+
25+
=head1 CONFIGURATION
26+
27+
[logstash_*]
28+
env.host 127.0.0.1
29+
env.port 9600
30+
31+
=head1 BUGS
32+
33+
None known so far. If you find any, let me know.
34+
35+
=head1 AUTHOR
36+
37+
Original Author:
38+
Tomas Doran (t0m) - c<< <[email protected]> >>
39+
Kentaro Yoshida - https://github.com/y-ken
40+
41+
Modified by Hirokazu MORIKAWA <[email protected]>
42+
43+
=cut
44+
45+
my $host = exists $ENV{'host'} ? $ENV{'host'} : 'localhost';
46+
my $port = exists $ENV{'port'} ? $ENV{'port'} : 9600;
47+
48+
my $ua = LWP::UserAgent->new;
49+
$ua->timeout(10);
50+
51+
sub get_json_from_url {
52+
my $uri = shift;
53+
my $res = $ua->get($uri, 'Content-Type' => 'application/json' );
54+
Carp::confess($res->code . " for " . $uri) unless $res->is_success;
55+
my $data = do { local $@; eval { decode_json($res->content) } };
56+
die("Could not decode JSON from: " . $res->content) unless $data;
57+
return $data;
58+
}
59+
60+
my $data = get_json_from_url("http://$host:$port/_node/stats/jvm");
61+
my %out = (heap_max => 0, heap_committed => 0, heap_used => 0, non_heap_committed => 0, non_heap_used => 0);
62+
63+
foreach my $name (grep { /_in_bytes$/ } keys %{ $data->{jvm}{mem} }) {
64+
my ($dname) = $name =~ m/(.+)_in_bytes$/;
65+
$out{$dname} += $data->{jvm}{mem}{$name};
66+
}
67+
68+
if ($ARGV[0] and $ARGV[0] eq 'config') {
69+
print "graph_args --base 1024\n";
70+
print "graph_title Logstash (port $port) JVM memory usage\n";
71+
print "graph_category logstash\n";
72+
print "graph_vlabel Bytes\n";
73+
74+
foreach my $name (keys %out) {
75+
print "$name.label $name\n"."$name.type GAUGE\n";
76+
}
77+
}
78+
elsif (!$ARGV[0] || $ARGV[0] eq 'autoconf') {
79+
foreach my $name (keys %out) {
80+
print "$name.value " . $out{$name} . "\n";
81+
}
82+
}
83+
84+
exit(0);

logstash_jvm_pools_size

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env perl
2+
3+
# Parameters supported:
4+
#
5+
# config
6+
# autoconf
7+
#
8+
# Magic markers:
9+
#%# family=auto
10+
#%# capabilities=autoconf
11+
12+
use strict;
13+
use warnings;
14+
use LWP;
15+
use JSON qw/decode_json/;
16+
17+
=head1 NAME
18+
19+
logstash_jvm_pools_size - A munin plugin that collects jvm pools size stats of your Logstash instances
20+
21+
=head1 APPLICABLE SYSTEMS
22+
23+
Logstash
24+
25+
=head1 CONFIGURATION
26+
27+
[logstash_*]
28+
env.host 127.0.0.1
29+
env.port 9600
30+
31+
=head1 BUGS
32+
33+
None known so far. If you find any, let me know.
34+
35+
=head1 AUTHOR
36+
37+
Original Author:
38+
Timothy Messier (t0m) - c<< <[email protected]> >>
39+
Kentaro Yoshida - https://github.com/y-ken
40+
41+
Modified by Hirokazu MORIKAWA <[email protected]>
42+
43+
=cut
44+
45+
my $host = exists $ENV{'host'} ? $ENV{'host'} : 'localhost';
46+
my $port = exists $ENV{'port'} ? $ENV{'port'} : 9600;
47+
48+
my $ua = LWP::UserAgent->new;
49+
$ua->timeout(10);
50+
51+
sub get_json_from_url {
52+
my $uri = shift;
53+
my $res = $ua->get($uri, 'Content-Type' => 'application/json' );
54+
Carp::confess($res->code . " for " . $uri) unless $res->is_success;
55+
my $data = do { local $@; eval { decode_json($res->content) } };
56+
die("Could not decode JSON from: " . $res->content) unless $data;
57+
return $data;
58+
}
59+
60+
my $data = get_json_from_url("http://$host:$port/_node/stats/jvm");
61+
my %out = (young_used => 0, young_peak => 0, survivor_used => 0, survivor_peak => 0, old_used => 0, old_peak => 0);
62+
63+
$out{young_used} += $data->{jvm}{mem}{pools}{young}{used_in_bytes};
64+
$out{young_peak} += $data->{jvm}{mem}{pools}{young}{peak_used_in_bytes};
65+
66+
$out{survivor_used} += $data->{jvm}{mem}{pools}{survivor}{used_in_bytes};
67+
$out{survivor_peak} += $data->{jvm}{mem}{pools}{survivor}{peak_used_in_bytes};
68+
69+
$out{old_used} += $data->{jvm}{mem}{pools}{old}{used_in_bytes};
70+
$out{old_peak} += $data->{jvm}{mem}{pools}{old}{peak_used_in_bytes};
71+
72+
if ($ARGV[0] and $ARGV[0] eq 'config') {
73+
print "graph_title Logstash (port $port) JVM pools size\n";
74+
print "graph_category logstash\n";
75+
print "graph_vlabel bytes\n";
76+
77+
foreach my $name (keys %out) {
78+
print "$name.label $name\n"."$name.type GAUGE\n";
79+
}
80+
}
81+
elsif (!$ARGV[0] || $ARGV[0] eq 'autoconf') {
82+
foreach my $name (keys %out) {
83+
print "$name.value " . $out{$name} . "\n";
84+
}
85+
}
86+
87+
exit(0);

logstash_jvm_threads

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env perl
2+
3+
# Parameters supported:
4+
#
5+
# config
6+
# autoconf
7+
#
8+
# Magic markers:
9+
#%# family=auto
10+
#%# capabilities=autoconf
11+
12+
use strict;
13+
use warnings;
14+
use LWP;
15+
use JSON qw/decode_json/;
16+
17+
=head1 NAME
18+
19+
logstash_jvm_threads - A munin plugin that collects stats from the JVM of your Logstash instances
20+
21+
=head1 APPLICABLE SYSTEMS
22+
23+
Logstash
24+
25+
=head1 CONFIGURATION
26+
27+
[logstash_*]
28+
env.host 127.0.0.1
29+
env.port 9600
30+
31+
=head1 BUGS
32+
33+
None known so far. If you find any, let me know.
34+
35+
=head1 AUTHOR
36+
37+
Original Author:
38+
Tomas Doran (t0m) - c<< <[email protected]> >>
39+
Kentaro Yoshida - https://github.com/y-ken
40+
41+
Modified by Hirokazu MORIKAWA <[email protected]>
42+
43+
=cut
44+
45+
my $host = exists $ENV{'host'} ? $ENV{'host'} : 'localhost';
46+
my $port = exists $ENV{'port'} ? $ENV{'port'} : 9600;
47+
48+
my $ua = LWP::UserAgent->new;
49+
$ua->timeout(10);
50+
51+
sub get_json_from_url {
52+
my $uri = shift;
53+
my $res = $ua->get($uri, 'Content-Type' => 'application/json' );
54+
Carp::confess($res->code . " for " . $uri) unless $res->is_success;
55+
my $data = do { local $@; eval { decode_json($res->content) } };
56+
die("Could not decode JSON from: " . $res->content) unless $data;
57+
return $data;
58+
}
59+
60+
my $data = get_json_from_url("http://$host:$port/_node/stats/jvm");
61+
my %out = (count => 0, peak_count => 0);
62+
63+
$out{count} = $data->{jvm}{threads}{count};
64+
$out{peak_count} = $data->{jvm}{threads}{peak_count};
65+
66+
if ($ARGV[0] and $ARGV[0] eq 'config') {
67+
print "graph_title Logstash (port $port) JVM threads\n";
68+
print "graph_category logstash\n";
69+
print "graph_scale no\n";
70+
71+
foreach my $name (keys %out) {
72+
print "$name.label $name\n"."$name.type GAUGE\n";
73+
}
74+
}
75+
elsif (!$ARGV[0] || $ARGV[0] eq 'autoconf') {
76+
foreach my $name (keys %out) {
77+
print "$name.value " . $out{$name} . "\n";
78+
}
79+
}
80+
81+
exit(0);

0 commit comments

Comments
 (0)