Last active
December 15, 2015 12:38
-
-
Save ysasaki/5261171 to your computer and use it in GitHub Desktop.
Munin plugin for Plack::Middleware::ServerStatus::Lite
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 | |
=pod | |
=head1 NAME | |
plack-middleware-serverstatus-lite - Munin plugin for Plack::Middleware::ServerStatus::Lite | |
=head1 INSTALL | |
# Download this script and create a symbolic link | |
> ln -s /path/to/this/script /etc/munin/plugins/your-service-name | |
=head1 ENV | |
env.title - Graph title. Default is 'Plack processes' | |
env.category - Graph category. Default is Plack | |
env.timeout - Timeout for request. Default is 3 secs. | |
env.agent - UserAgent. Default is 'plack-middleware-serverstatus-lite/$VERSION'; | |
env.url - Server status url to request. Default is http://localhost:5000/server-status?json | |
env.username - For BASIC authentication. Optional. | |
env.password - For BASIC authentication. Optional. | |
=head1 DEPENDENCIES | |
L<JSON>, L<LWP::UserAgent> | |
=head1 AUTHOR | |
Yoshihiro Sasaki E<lt>ysasaki at cpan.orgE<gt> | |
=head1 LICENSE | |
This library is free software; you can redistribute it and/or modify | |
it under the same terms as Perl itself. | |
=head1 COPYRIGHT | |
Copyright (C) 2013 by Yoshihiro Sasaki | |
=cut | |
use strict; | |
use warnings; | |
use JSON; | |
use LWP::UserAgent; | |
our $VERSION = '0.0.1'; | |
if ( exists $ARGV[0] and $ARGV[0] eq 'config' ) { | |
my $title = $ENV{title} || 'Plack processes'; | |
my $category = $ENV{category} || 'Plack'; | |
my $config_format = << "CFORMAT"; | |
graph_title $title | |
graph_args --base 1000 -l 0 | |
graph_category $category | |
graph_order busy idle | |
graph_vlabel processes | |
graph_total total | |
busy.label busy servers | |
busy.draw AREA | |
idle.label idle servers | |
idle.draw STACK | |
CFORMAT | |
print $config_format; | |
exit; | |
} | |
my $timeout = $ENV{timeout} || 3; | |
my $agent = $ENV{agent} | |
|| "plack-middleware-serverstatus-lite/$VERSION"; | |
my $url = $ENV{url} || 'http://localhost:5000/server-status?json'; | |
my $ua = LWP::UserAgent->new( | |
timeout => $timeout, | |
agent => $agent, | |
); | |
my $request = HTTP::Request->new( GET => $url ); | |
if ( $ENV{username} && $ENV{password} ) { | |
$request->authorization_basic( $ENV{username}, $ENV{password} ); | |
} | |
my $response = $ua->request($request); | |
if ( $response->is_success ) { | |
my $data = decode_json $response->content; | |
printf <<"FORMAT", $data->{BusyWorkers}, $data->{IdleWorkers}; | |
busy.value %d | |
idle.value %d | |
FORMAT | |
exit 0; | |
} | |
else { | |
warn "Request faied: " . $response->status_line; | |
exit 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment