root / plugins / other / nginx_request @ 9e9466fe
Historique | Voir | Annoter | Télécharger (1,27 ko)
| 1 | a83ae019 | unkown | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # |
||
| 3 | # Magic markers: |
||
| 4 | #%# family=auto |
||
| 5 | #%# capabilities=autoconf |
||
| 6 | |||
| 7 | my $ret = undef; |
||
| 8 | |||
| 9 | if (! eval "require LWP::UserAgent;"){
|
||
| 10 | $ret = "LWP::UserAgent not found"; |
||
| 11 | } |
||
| 12 | |||
| 13 | chomp(my $fqdn=`hostname -f`); |
||
| 14 | |||
| 15 | my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status";
|
||
| 16 | |||
| 17 | if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) |
||
| 18 | {
|
||
| 19 | if ($ret){
|
||
| 20 | print "no ($ret)\n"; |
||
| 21 | exit 1; |
||
| 22 | } |
||
| 23 | |||
| 24 | my $ua = LWP::UserAgent->new(timeout => 30); |
||
| 25 | my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
||
| 26 | |||
| 27 | unless ($response->is_success and $response->content =~ /server/im) |
||
| 28 | {
|
||
| 29 | print "no (no nginx status on $URL)\n"; |
||
| 30 | exit 1; |
||
| 31 | } |
||
| 32 | else |
||
| 33 | {
|
||
| 34 | print "yes\n"; |
||
| 35 | exit 0; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | if ( exists $ARGV[0] and $ARGV[0] eq "config" ) |
||
| 40 | {
|
||
| 41 | print "graph_title NGINX requests\n"; |
||
| 42 | print "graph_args --base 1000\n"; |
||
| 43 | print "graph_category nginx\n"; |
||
| 44 | print "graph_vlabel Request per second\n"; |
||
| 45 | |||
| 46 | print "request.label req/sec\n"; |
||
| 47 | print "request.type DERIVE\n"; |
||
| 48 | print "request.min 0\n"; |
||
| 49 | print "request.label requests $port\n"; |
||
| 50 | print "request.draw LINE2\n"; |
||
| 51 | |||
| 52 | exit 0; |
||
| 53 | } |
||
| 54 | |||
| 55 | my $ua = LWP::UserAgent->new(timeout => 30); |
||
| 56 | |||
| 57 | my $response = $ua->request(HTTP::Request->new('GET',$URL));
|
||
| 58 | |||
| 59 | if ($response->content =~ /^\s+(\d+)\s+(\d+)\s+(\d+)/m) {
|
||
| 60 | print "request.value $3\n"; |
||
| 61 | } else {
|
||
| 62 | print "request.value U\n"; |
||
| 63 | } |
