From ef7dbfa6b6d13df547b7f60f835d427f1737e140 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 9 Nov 2018 13:06:18 +0100 Subject: [PATCH] Add simple script for nginx (similar httpd) --- zabbix_conf/nginx.conf | 5 ++++ zabbix_scripts/check_nginx | 56 ++++++++++++++++++++++++++++++++++++++ zabbix_scripts/disco_nginx | 18 ++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 zabbix_conf/nginx.conf create mode 100755 zabbix_scripts/check_nginx create mode 100755 zabbix_scripts/disco_nginx diff --git a/zabbix_conf/nginx.conf b/zabbix_conf/nginx.conf new file mode 100644 index 0000000..d7d723c --- /dev/null +++ b/zabbix_conf/nginx.conf @@ -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 diff --git a/zabbix_scripts/check_nginx b/zabbix_scripts/check_nginx new file mode 100755 index 0000000..f3d19ab --- /dev/null +++ b/zabbix_scripts/check_nginx @@ -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; diff --git a/zabbix_scripts/disco_nginx b/zabbix_scripts/disco_nginx new file mode 100755 index 0000000..8a0885a --- /dev/null +++ b/zabbix_scripts/disco_nginx @@ -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);