mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Addded POD and an additional User Agent environment variable
This commit is contained in:
parent
5ea89f41dc
commit
7a00481e94
@ -1,43 +1,137 @@
|
|||||||
#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
||||||
#
|
# -*- cperl -*-
|
||||||
# Magic markers:
|
# Magic markers:
|
||||||
#%# family=auto
|
#%# family=auto
|
||||||
#%# capabilities=autoconf
|
#%# capabilities=autoconf
|
||||||
|
# nginx_status --- Determine the current status of Nginx
|
||||||
|
# using the http_stub_status module.
|
||||||
|
|
||||||
|
# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net>
|
||||||
|
|
||||||
|
# Author: António P. P. Almeida <appa@perusio.net>
|
||||||
|
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
# copy of this software and associated documentation files (the "Software"),
|
||||||
|
# to deal in the Software without restriction, including without limitation
|
||||||
|
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
# and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
# Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
# Except as contained in this notice, the name(s) of the above copyright
|
||||||
|
# holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
|
# use or other dealings in this Software without prior written authorization.
|
||||||
|
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
nginx_status - Munin plugin to show the connection status for nginx
|
||||||
|
|
||||||
|
=encoding utf8
|
||||||
|
|
||||||
|
=head1 APPLICABLE SYSTEMS
|
||||||
|
|
||||||
|
Any nginx host
|
||||||
|
|
||||||
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
|
This shows the default configuration of this plugin. You can override
|
||||||
|
the status URL and the User Agent.
|
||||||
|
|
||||||
|
[nginx*]
|
||||||
|
env.url http://localhost/nginx_status
|
||||||
|
env.ua nginx-status-verifier/0.1
|
||||||
|
|
||||||
|
Nginx must also be configured. Firstly the stub-status module must be
|
||||||
|
compiled, and secondly it must be configured like this:
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 127.0.0.1;
|
||||||
|
server_name localhost;
|
||||||
|
location /nginx_status {
|
||||||
|
stub_status on;
|
||||||
|
access_log off;
|
||||||
|
allow 127.0.0.1;
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
=head1 MAGIC MARKERS
|
||||||
|
|
||||||
|
#%# family=auto
|
||||||
|
#%# capabilities=autoconf
|
||||||
|
|
||||||
|
=head1 VERSION
|
||||||
|
|
||||||
|
1.1
|
||||||
|
|
||||||
|
=head1 BUGS
|
||||||
|
|
||||||
|
None known
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Unknown. Mantained by António Almeida <appa@perusio.net>
|
||||||
|
|
||||||
|
=head1 REPOSITORY
|
||||||
|
|
||||||
|
Source code at http://github.com/perusio/nginx-munin
|
||||||
|
|
||||||
|
=head1 LICENSE
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
my $ret = undef;
|
my $ret = undef;
|
||||||
|
|
||||||
if (! eval "require LWP::UserAgent;"){
|
if (! eval "require LWP::UserAgent;") {
|
||||||
$ret = "LWP::UserAgent not found";
|
$ret = "LWP::UserAgent not found";
|
||||||
}
|
}
|
||||||
|
|
||||||
chomp(my $fqdn=`hostname -f`);
|
chomp(my $fqdn=`hostname -f`);
|
||||||
|
|
||||||
|
## Environment defined variables.
|
||||||
|
## The default URL is nginx_status if different set it in the environment.
|
||||||
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status";
|
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status";
|
||||||
|
## The default user agent is ngnix-status-verifier/0.1 if different
|
||||||
|
## set it in the environment.
|
||||||
|
my $UA = exists $ENV{'ua'} ? $ENV{'ua'} : 'nginx-status-verifier/0.1';
|
||||||
|
|
||||||
if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" )
|
|
||||||
{
|
## Munin autoconf method.
|
||||||
if ($ret){
|
if (exists $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
||||||
|
if ($ret) {
|
||||||
print "no ($ret)\n";
|
print "no ($ret)\n";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new(timeout => 30);
|
my $ua = LWP::UserAgent->new(timeout => 30);
|
||||||
|
# Set the UA to something different from the libwww-perl.
|
||||||
|
# This UA is blocked.
|
||||||
|
$ua->agent($UA);
|
||||||
my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
||||||
|
|
||||||
unless ($response->is_success and $response->content =~ /server/im)
|
unless ($response->is_success and $response->content =~ /server/im) {
|
||||||
{
|
|
||||||
print "no (no nginx status on $URL)\n";
|
print "no (no nginx status on $URL)\n";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
print "yes\n";
|
print "yes\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( exists $ARGV[0] and $ARGV[0] eq "config" )
|
## Munin config method.
|
||||||
{
|
if (exists $ARGV[0] and $ARGV[0] eq "config") {
|
||||||
print "graph_title NGINX status\n";
|
print "graph_title NGINX status\n";
|
||||||
print "graph_args --base 1000\n";
|
print "graph_args --base 1000\n";
|
||||||
print "graph_category nginx\n";
|
print "graph_category nginx\n";
|
||||||
@ -63,11 +157,13 @@ if ( exists $ARGV[0] and $ARGV[0] eq "config" )
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new(timeout => 30);
|
my $ua = LWP::UserAgent->new(timeout => 30);
|
||||||
|
# Set the UA to something different from the libwww-perl.
|
||||||
|
# That UA is blocked.
|
||||||
|
$ua->agent($UA);
|
||||||
my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
||||||
|
|
||||||
#Active connections: 1845
|
# Active connections: 1845
|
||||||
#server accepts handled requests
|
# server accepts handled requests
|
||||||
# 4566318 4566318 84218236
|
# 4566318 4566318 84218236
|
||||||
# Reading: 2 Writing: 278 Waiting: 1565
|
# Reading: 2 Writing: 278 Waiting: 1565
|
||||||
if ($response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s) {
|
if ($response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s) {
|
||||||
@ -76,7 +172,7 @@ if ($response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writin
|
|||||||
print "writing.value $3\n";
|
print "writing.value $3\n";
|
||||||
print "waiting.value $4\n";
|
print "waiting.value $4\n";
|
||||||
} else {
|
} else {
|
||||||
foreach (qw(total reading writing waiting)){
|
foreach (qw(total reading writing waiting)) {
|
||||||
print "$_.value U\n";
|
print "$_.value U\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user