Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* First public release of the complete set with a README.

  • Loading branch information...
commit d706414ad3f2a2f878b65b7393e500d3497c9e29 1 parent f6bbef4
@perusio authored
Showing with 173 additions and 13 deletions.
  1. +76 −0 README.org
  2. +86 −0 nginx_memory
  3. +9 −11 nginx_request
  4. +2 −2 nginx_status
View
76 README.org
@@ -0,0 +1,76 @@
+* Nginx requests, memory usage and connections statistics with Munin
+
+** Introduction
+
+ These three perl scripts are [[http://munin-monitoring.org][Munin]] plugins for monitoring the [[http://nginx.org][nginx]]
+ HTTP server.
+
+** nginx_status
+
+ Based on the one provided in the Debian [[http://packages.debian.org/squeeze/munin-node][munin-node]] package. Which
+ is itself a modified version of the one available at the [[http://exchange.munin-monitoring.org][Munin Plugin
+ Exchange]].
+
+** nginx_request
+
+ Based on the one provided in the Debian [[http://packages.debian.org/squeeze/munin-node][munin-node]] package. Which
+ is itself a modified version of the one available at the [[http://exchange.munin-monitoring.org][Munin Plugin
+ Exchange]].
+
+ The original version computed *nonsensical* values. The values
+ returned by nginx, using the [[wiki.nginx.org/NginxHttpStubStatusModule][http_stub_status]] module, are
+ respectively, the number of:
+
+ /connections initiated/, /connections handled/, /requests served/
+
+ The connection rate handled by the server is the ratio:
+
+ requests served / connections handled
+
+ This is implemented as a RRDtool datasource of type =GAUGE=, the
+ [[http://munin-monitoring.org/wiki/fieldname.type][default]] type for Munin.
+
+** nginx_memory
+
+ Based on a previous plugin by AkyRhO. It uses =ps= and =awk= to get
+ the memory used by the master and worker processes of nginx.
+
+** Installation & Configuration
+
+
+ 1. Copy all the scripts to =/etc/munin/plugins=.
+
+ 2. Restart the munin-node daemon. =/etc/init.d/munin-node restart=.
+
+ 3. Done. You should now start to see a new section *nginx* in your
+ Munin pages with the corresponding graphs.
+
+** Environment Settings
+
+ Both =nginx_request= and =nginx_status= accept *two* environment
+ variables:
+
+ + URL: the URL of the nginx status data. The default value is:
+
+ =http://hostname/nginx_status=
+
+ + UA: the User Agent that the plugin sends in the HTTP
+ header. Since most sites block the libwww-* user agent to get rid
+ of bad bots and mostly up to no good scanners, the scripts send a
+ different User Agent to get around that.
+
+ Both variables can be specified in the
+ =/etc/munin/plugin-conf.d/munin-node= file.
+
+ Something like this for altering the URL:
+
+ =[nginx_status]=
+ =env.url=http://hostname:8888/nginx-status nginx_status=
+
+ =[nginx_request]=
+ =env.url=http://hostname:8888/nginx-status nginx_status=
+
+ Add =env.ua= for altering the User Agent.
+
+ Don't forget to restart the munin-node daemon as described in step
+ 2 of the installation instructions above.
View
86 nginx_memory
@@ -0,0 +1,86 @@
+#!/usr/bin/perl -w
+# -*- mode: cperl; mode: autopair -*-
+# Magic markers:
+#%# family=auto
+#%# capabilities=autoconf
+# nginx_memory --- Munin plugin for monitoring Nginx memory
+# usage. Based on the nginx_memory.pl plugin
+# by AkyRhO <akyrho@gmail.com>.
+
+# 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_memory - Munin plugin to show the RAM used by nginx.
+
+=encoding utf8
+
+=head1 APPLICABLE SYSTEMS
+
+Any nginx host
+
+=head1 MAGIC MARKERS
+
+ #%# family=auto
+ #%# capabilities=autoconf
+
+=head1 VERSION
+
+1.0
+
+=head1 BUGS
+
+None known
+
+=head1 AUTHOR
+
+Based on a script by AkyRhO <akyrho@gmail.com>. Modified by António
+Almeida <appa@perusio.net>
+
+=head1 REPOSITORY
+
+Source code at http://github.com/perusio/nginx-munin
+
+=head1 LICENSE
+
+MIT
+
+=cut
+
+## Munin config method.
+if (exists $ARGV[0] and $ARGV[0] eq "config") {
+ print "graph_title nginx RAM usage\n";
+ print "graph_vlabel RAM\n";
+ print "graph_category nginx\n";
+ print "ram.label RAM\n";
+ print "graph_args --base 1024\n";
+
+ exit 0;
+} else {
+ my $m = `ps u -p \$(pidof nginx) | awk 'NR > 1 {nm += \$5} END {print nm*1024}'`;
+ print "ram.value $m";
+}
View
20 nginx_request
@@ -1,9 +1,11 @@
#!/usr/bin/perl -w
-# -*- cperl -*-
+# -*- mode: cperl; mode: autopair -*-
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
-# nginx_request --- Determine the current connection rate for Nginx.
+# nginx_request --- Determine the current connection rate for
+# nginx. Based on a nginx_request plugin by unknown
+# author.
# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net>
@@ -79,7 +81,7 @@ None known
=head1 AUTHOR
-Unknown Mantained by António Almeida <appa@perusio.net>
+Unknown. Modified by António Almeida <appa@perusio.net>
=head1 REPOSITORY
@@ -91,7 +93,6 @@ MIT
=cut
-
my $ret = undef;
if (! eval "require LWP::UserAgent;") {
@@ -130,13 +131,10 @@ if (exists $ARGV[0] and $ARGV[0] eq "autoconf" ) {
## Munin config method.
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
- print "graph_title NGINX requests\n";
- print "graph_args --base 1000\n";
+ print "graph_title nginx requests/second rate\n";
print "graph_category nginx\n";
- print "graph_vlabel Request per second\n";
- print "request.label requests\n";
- print "request.label req/sec\n";
- print "request.type DERIVE\n";
+ print "graph_vlabel Request Rate\n";
+ print "request.label requests/second\n";
print "request.min 0\n";
print "request.draw LINE2\n";
@@ -150,7 +148,7 @@ $ua->agent($UA);
my $response = $ua->request(HTTP::Request->new('GET',$URL));
if ($response->content =~ /^\s+(\d+)\s+(\d+)\s+(\d+)/m) {
- print "request.value $3\n";
+ printf("request.value %.2f\n", $3/$2);
} else {
print "request.value U\n";
}
View
4 nginx_status
@@ -162,8 +162,8 @@ my $ua = LWP::UserAgent->new(timeout => 30);
$ua->agent($UA);
my $response = $ua->request(HTTP::Request->new('GET',$URL));
-#Active connections: 1845
-#server accepts handled requests
+# Active connections: 1845
+# server accepts handled requests
# 4566318 4566318 84218236
# Reading: 2 Writing: 278 Waiting: 1565
if ($response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s) {
Please sign in to comment.
Something went wrong with that request. Please try again.