root / plugins / other / nginx_status @ 7a00481e
Historique | Voir | Annoter | Télécharger (4,83 ko)
| 1 | dc892da5 | unkown | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | 7a00481e | perusio | # -*- cperl -*- |
| 3 | dc892da5 | unkown | # Magic markers: |
| 4 | #%# family=auto |
||
| 5 | #%# capabilities=autoconf |
||
| 6 | 7a00481e | perusio | # nginx_status --- Determine the current status of Nginx |
| 7 | # using the http_stub_status module. |
||
| 8 | |||
| 9 | # Copyright (C) 2010 António P. P. Almeida <appa@perusio.net> |
||
| 10 | |||
| 11 | # Author: António P. P. Almeida <appa@perusio.net> |
||
| 12 | |||
| 13 | # Permission is hereby granted, free of charge, to any person obtaining a |
||
| 14 | # copy of this software and associated documentation files (the "Software"), |
||
| 15 | # to deal in the Software without restriction, including without limitation |
||
| 16 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
| 17 | # and/or sell copies of the Software, and to permit persons to whom the |
||
| 18 | # Software is furnished to do so, subject to the following conditions: |
||
| 19 | |||
| 20 | # The above copyright notice and this permission notice shall be included in |
||
| 21 | # all copies or substantial portions of the Software. |
||
| 22 | |||
| 23 | # Except as contained in this notice, the name(s) of the above copyright |
||
| 24 | # holders shall not be used in advertising or otherwise to promote the sale, |
||
| 25 | # use or other dealings in this Software without prior written authorization. |
||
| 26 | |||
| 27 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
| 28 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
| 29 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
| 30 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
| 31 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
| 32 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
| 33 | # DEALINGS IN THE SOFTWARE. |
||
| 34 | |||
| 35 | =head1 NAME |
||
| 36 | |||
| 37 | nginx_status - Munin plugin to show the connection status for nginx |
||
| 38 | |||
| 39 | =encoding utf8 |
||
| 40 | |||
| 41 | =head1 APPLICABLE SYSTEMS |
||
| 42 | |||
| 43 | Any nginx host |
||
| 44 | |||
| 45 | =head1 CONFIGURATION |
||
| 46 | |||
| 47 | This shows the default configuration of this plugin. You can override |
||
| 48 | the status URL and the User Agent. |
||
| 49 | |||
| 50 | [nginx*] |
||
| 51 | env.url http://localhost/nginx_status |
||
| 52 | env.ua nginx-status-verifier/0.1 |
||
| 53 | |||
| 54 | Nginx must also be configured. Firstly the stub-status module must be |
||
| 55 | compiled, and secondly it must be configured like this: |
||
| 56 | |||
| 57 | server {
|
||
| 58 | listen 127.0.0.1; |
||
| 59 | server_name localhost; |
||
| 60 | location /nginx_status {
|
||
| 61 | stub_status on; |
||
| 62 | access_log off; |
||
| 63 | allow 127.0.0.1; |
||
| 64 | deny all; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | =head1 MAGIC MARKERS |
||
| 69 | |||
| 70 | #%# family=auto |
||
| 71 | #%# capabilities=autoconf |
||
| 72 | |||
| 73 | =head1 VERSION |
||
| 74 | |||
| 75 | 1.1 |
||
| 76 | |||
| 77 | =head1 BUGS |
||
| 78 | |||
| 79 | None known |
||
| 80 | |||
| 81 | =head1 AUTHOR |
||
| 82 | |||
| 83 | Unknown. Mantained by António Almeida <appa@perusio.net> |
||
| 84 | |||
| 85 | =head1 REPOSITORY |
||
| 86 | |||
| 87 | Source code at http://github.com/perusio/nginx-munin |
||
| 88 | |||
| 89 | =head1 LICENSE |
||
| 90 | |||
| 91 | MIT |
||
| 92 | |||
| 93 | =cut |
||
| 94 | dc892da5 | unkown | |
| 95 | my $ret = undef; |
||
| 96 | |||
| 97 | 7a00481e | perusio | if (! eval "require LWP::UserAgent;") {
|
| 98 | $ret = "LWP::UserAgent not found"; |
||
| 99 | dc892da5 | unkown | } |
| 100 | |||
| 101 | chomp(my $fqdn=`hostname -f`); |
||
| 102 | |||
| 103 | 7a00481e | perusio | ## Environment defined variables. |
| 104 | ## The default URL is nginx_status if different set it in the environment. |
||
| 105 | dc892da5 | unkown | my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status";
|
| 106 | 7a00481e | perusio | ## The default user agent is ngnix-status-verifier/0.1 if different |
| 107 | ## set it in the environment. |
||
| 108 | my $UA = exists $ENV{'ua'} ? $ENV{'ua'} : 'nginx-status-verifier/0.1';
|
||
| 109 | dc892da5 | unkown | |
| 110 | 7a00481e | perusio | |
| 111 | ## Munin autoconf method. |
||
| 112 | if (exists $ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
||
| 113 | if ($ret) {
|
||
| 114 | print "no ($ret)\n"; |
||
| 115 | exit 1; |
||
| 116 | } |
||
| 117 | |||
| 118 | my $ua = LWP::UserAgent->new(timeout => 30); |
||
| 119 | # Set the UA to something different from the libwww-perl. |
||
| 120 | # This UA is blocked. |
||
| 121 | $ua->agent($UA); |
||
| 122 | my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
||
| 123 | |||
| 124 | unless ($response->is_success and $response->content =~ /server/im) {
|
||
| 125 | print "no (no nginx status on $URL)\n"; |
||
| 126 | exit 1; |
||
| 127 | } else {
|
||
| 128 | print "yes\n"; |
||
| 129 | exit 0; |
||
| 130 | } |
||
| 131 | dc892da5 | unkown | } |
| 132 | |||
| 133 | 7a00481e | perusio | ## Munin config method. |
| 134 | if (exists $ARGV[0] and $ARGV[0] eq "config") {
|
||
| 135 | print "graph_title NGINX status\n"; |
||
| 136 | print "graph_args --base 1000\n"; |
||
| 137 | print "graph_category nginx\n"; |
||
| 138 | print "graph_vlabel Connections\n"; |
||
| 139 | |||
| 140 | print "total.label Active connections\n"; |
||
| 141 | print "total.info Active connections\n"; |
||
| 142 | print "total.draw LINE2\n"; |
||
| 143 | |||
| 144 | print "reading.label Reading\n"; |
||
| 145 | print "reading.info Reading\n"; |
||
| 146 | print "reading.draw LINE2\n"; |
||
| 147 | |||
| 148 | print "writing.label Writing\n"; |
||
| 149 | print "writing.info Writing\n"; |
||
| 150 | print "writing.draw LINE2\n"; |
||
| 151 | |||
| 152 | print "waiting.label Waiting\n"; |
||
| 153 | print "waiting.info Waiting\n"; |
||
| 154 | print "waiting.draw LINE2\n"; |
||
| 155 | |||
| 156 | exit 0; |
||
| 157 | dc892da5 | unkown | } |
| 158 | |||
| 159 | my $ua = LWP::UserAgent->new(timeout => 30); |
||
| 160 | 7a00481e | perusio | # Set the UA to something different from the libwww-perl. |
| 161 | # That UA is blocked. |
||
| 162 | $ua->agent($UA); |
||
| 163 | dc892da5 | unkown | my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
| 164 | |||
| 165 | 7a00481e | perusio | # Active connections: 1845 |
| 166 | # server accepts handled requests |
||
| 167 | # 4566318 4566318 84218236 |
||
| 168 | # Reading: 2 Writing: 278 Waiting: 1565 |
||
| 169 | dc892da5 | unkown | if ($response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s) {
|
| 170 | 7a00481e | perusio | print "total.value $1\n"; |
| 171 | print "reading.value $2\n"; |
||
| 172 | print "writing.value $3\n"; |
||
| 173 | print "waiting.value $4\n"; |
||
| 174 | dc892da5 | unkown | } else {
|
| 175 | 7a00481e | perusio | foreach (qw(total reading writing waiting)) {
|
| 176 | print "$_.value U\n"; |
||
| 177 | } |
||
| 178 | dc892da5 | unkown | } |
