Add simple script for nginx (similar httpd)

tags/zabbix-agent-addons-0.2.56-1
Daniel Berteaud 6 years ago
parent cf40711197
commit ef7dbfa6b6
  1. 5
      zabbix_conf/nginx.conf
  2. 56
      zabbix_scripts/check_nginx
  3. 18
      zabbix_scripts/disco_nginx

@ -0,0 +1,5 @@
# Discover if an nginx instance is running and has status handler running on http://localhost/nginx-status
UserParameter=nginx.discovery,/var/lib/zabbix/bin/disco_nginx
# Stats to get
UserParameter=nginx.status[*],/var/lib/zabbix/bin/check_nginx --uri $1 --what $2

@ -0,0 +1,56 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::Simple;
use Getopt::Long;
use JSON;
my $uri = 'http://127.0.0.1/nginx-status';
my $what = 'all';
my $help = 0;
my $pretty = 0;
GetOptions(
"uri=s" => \$uri,
"what=s" => \$what,
"help" => \$help,
"pretty" => \$pretty
);
my $res = {};
my $status = get($uri);
unless ($status){
print 'ZBX_UNSUPPOTED';
exit 1;
}
foreach my $line (split(/\n/, $status)){
if ($line =~ m/^Active connections: (\d+)/){
$res->{active_connections} = $1;
} elsif ($line =~ m/\s*(\d+)\s+\d+\s+(\d+)/){
$res->{total_connections} = $1;
$res->{total_requests} = $2;
} elsif ($line =~ m/Waiting: (\d+)/){
$res->{keep_alive} = $1;
}
}
if ($help){
print "Valid keys are:\n\n";
print "$_\n" for keys %{$res};
exit 0;
}
if ($what eq 'all'){
print to_json($res, { pretty => $pretty });
}
elsif (defined $res->{$what}){
print $res->{$what};
}
else{
print 'ZBX_UNSUPPOTED';
}
exit 0;

@ -0,0 +1,18 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::Simple;
use JSON;
my $json;
@{$json->{data}} = ();
my $status = get('http://127.0.0.1/nginx-status');
if ($status){
push @{$json->{data}}, {"{#NGINX_STATUS_URI}" => 'http://127.0.0.1/nginx-status'};
}
print to_json($json);
exit(0);
Loading…
Cancel
Save