2010-09-13 15:53:31 +02:00
|
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
# -*- cperl -*-
|
|
|
|
|
# Magic markers:
|
|
|
|
|
#%# family=auto
|
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
# nginx_combine_ --- Determine the current status of Nginx
|
|
|
|
|
# using the http_stub_status module.
|
|
|
|
|
# extend of nginx_status_ plugin of Ant<6E>nio P. P. Almeida
|
|
|
|
|
|
|
|
|
|
# Copyright (C) 2010 Ant<6E>nio P. P. Almeida <appa@perusio.net>
|
|
|
|
|
# Copyright (C) 2010 Minato Miray <minatomiray@gmail.com>
|
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|
# Author: Ant<6E>nio P. P. Almeida <appa@perusio.net>,
|
2010-09-13 15:53:31 +02:00
|
|
|
|
# Author: Minato Miray <minatomiray@gmail.com>
|
|
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
|
# Nginx combined plugin to measure in one graph:
|
|
|
|
|
# - Request /sec
|
|
|
|
|
# - Connection / sec
|
|
|
|
|
# - Request / connection
|
|
|
|
|
# - Active connections
|
|
|
|
|
# - Reading
|
|
|
|
|
# - Writing
|
|
|
|
|
# - Waiting
|
|
|
|
|
########################################
|
|
|
|
|
|
|
|
|
|
# Usage:
|
|
|
|
|
# Copy to /usr/share/munin/plugins
|
|
|
|
|
# ln -s /usr/share/munin/plugins/nginx_combined_ /etc/munin/plugins/nginx_combined_[hostname OR IP address]
|
|
|
|
|
|
|
|
|
|
#examples based on nginx configuration:
|
|
|
|
|
#example1: ./nginx_combined_mysite.net
|
|
|
|
|
#example2: ./nginx_combined_10.0.0.1
|
|
|
|
|
|
|
|
|
|
########################################
|
|
|
|
|
|
|
|
|
|
my $ret = undef;
|
|
|
|
|
|
|
|
|
|
if (! eval "require LWP::UserAgent;"){
|
|
|
|
|
$ret = "LWP::UserAgent not found";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chomp(my $fqdn = `basename $0 | sed 's/^nginx_combined_//g'`);
|
|
|
|
|
|
|
|
|
|
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status";
|
|
|
|
|
|
|
|
|
|
if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" )
|
|
|
|
|
{
|
|
|
|
|
if ($ret){
|
|
|
|
|
print "no ($ret)\n";
|
|
|
|
|
exit 1;
|
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
|
|
2010-09-13 15:53:31 +02:00
|
|
|
|
my $ua = LWP::UserAgent->new(timeout => 30);
|
|
|
|
|
my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
|
|
|
|
|
|
|
|
|
unless ($response->is_success and $response->content =~ /server/im)
|
|
|
|
|
{
|
|
|
|
|
print "no (no nginx status on $URL)\n";
|
|
|
|
|
exit 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
print "yes\n";
|
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( exists $ARGV[0] and $ARGV[0] eq "config" )
|
|
|
|
|
{
|
|
|
|
|
print "graph_title NGINX status: $URL\n";
|
|
|
|
|
print "graph_args --base 1000\n";
|
2017-02-21 17:11:23 +01:00
|
|
|
|
print "graph_category webserver\n";
|
2010-09-13 15:53:31 +02:00
|
|
|
|
print "graph_vlabel Connections\n";
|
|
|
|
|
|
|
|
|
|
print "reqpsec.label Request/sec.\n";
|
|
|
|
|
print "reqpsec.info Request/sec.\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
print "reqpsec.draw LINE2\n";
|
2010-09-13 15:53:31 +02:00
|
|
|
|
|
|
|
|
|
print "conpersec.label Connection/sec.\n";
|
|
|
|
|
print "conpersec.info Connection/sec.\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
print "conpersec.draw LINE2\n";
|
2010-09-13 15:53:31 +02:00
|
|
|
|
|
|
|
|
|
print "reqpcon.label Request/conn.\n";
|
|
|
|
|
print "reqpcon.info Request/conn.\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
print "reqpcon.draw LINE2\n";
|
2010-09-13 15:53:31 +02:00
|
|
|
|
|
|
|
|
|
print "total.label Active connections\n";
|
|
|
|
|
print "total.info Active connections\n";
|
|
|
|
|
print "total.draw LINE2\n";
|
|
|
|
|
|
|
|
|
|
print "reading.label Reading\n";
|
|
|
|
|
print "reading.info Reading\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
print "reading.draw LINE2\n";
|
2010-09-13 15:53:31 +02:00
|
|
|
|
|
|
|
|
|
print "writing.label Writing\n";
|
|
|
|
|
print "writing.info Writing\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
print "writing.draw LINE2\n";
|
2010-09-13 15:53:31 +02:00
|
|
|
|
|
|
|
|
|
print "waiting.label Waiting\n";
|
|
|
|
|
print "waiting.info Waiting\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
print "waiting.draw LINE2\n";
|
|
|
|
|
|
2010-09-13 15:53:31 +02:00
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#do requests
|
|
|
|
|
my $ua = LWP::UserAgent->new(timeout => 10);
|
|
|
|
|
my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
|
|
|
|
sleep(1);
|
|
|
|
|
my $response2 = $ua->request(HTTP::Request->new('GET',$URL));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#calculate responses
|
|
|
|
|
$response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s;
|
|
|
|
|
my $a1 = $1;
|
|
|
|
|
my $r1 = $2;
|
|
|
|
|
my $w1 = $3;
|
|
|
|
|
my $wa1 = $4;
|
|
|
|
|
|
|
|
|
|
my $out1 = $response->content;
|
|
|
|
|
$out1 =~ s/\n/ /g;
|
|
|
|
|
my @vals = split(/ /, $out1);
|
|
|
|
|
|
|
|
|
|
my $tmp1_reqpsec=$vals[11];
|
|
|
|
|
my $tmp1_conpsec=$vals[10];
|
|
|
|
|
|
|
|
|
|
$response2->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s;
|
|
|
|
|
|
|
|
|
|
my $a2 = $1;
|
|
|
|
|
my $r2 = $2;
|
|
|
|
|
my $w2 = $3;
|
|
|
|
|
my $wa2 = $4;
|
|
|
|
|
|
|
|
|
|
my $out2 = $response2->content;
|
|
|
|
|
$out2 =~ s/\n/ /g;
|
|
|
|
|
my @vals2 = split(/ /, $out2);
|
|
|
|
|
my $tmp2_reqpsec=$vals2[11];
|
|
|
|
|
my $tmp2_conpsec=$vals2[10];
|
|
|
|
|
|
2010-12-02 14:01:32 +01:00
|
|
|
|
my $conpersec=0;
|
2010-09-13 15:53:31 +02:00
|
|
|
|
my $reqpcon=0;
|
|
|
|
|
my $reqpsec=0;
|
|
|
|
|
if (defined $tmp2_conpsec && $tmp2_conpsec =~ /^[+-]?\d+$/ && $tmp2_conpsec > 0){
|
|
|
|
|
$conpersec=$tmp2_conpsec-$tmp1_conpsec;
|
|
|
|
|
}
|
|
|
|
|
if (defined $tmp2_reqpsec && $tmp2_reqpsec =~ /^[+-]?\d+$/ && $tmp2_reqpsec > 0){
|
2018-08-02 02:03:42 +02:00
|
|
|
|
$reqpsec=$tmp2_reqpsec-$tmp1_reqpsec;
|
2010-09-13 15:53:31 +02:00
|
|
|
|
}
|
|
|
|
|
if ($conpersec > 0){
|
|
|
|
|
$reqpcon=$reqpsec/$conpersec;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
}
|
2010-12-02 14:01:32 +01:00
|
|
|
|
|
|
|
|
|
print "reqpsec.value $reqpsec\n";
|
|
|
|
|
print "conpersec.value $conpersec\n";
|
|
|
|
|
printf("reqpcon.value %.2f\n", $reqpcon);
|
|
|
|
|
print "total.value $a2\n";
|
|
|
|
|
print "reading.value $r2\n";
|
|
|
|
|
print "writing.value $w2\n";
|
|
|
|
|
print "waiting.value $wa2\n";
|
2010-09-13 15:53:31 +02:00
|
|
|
|
|