Pages

Tuesday, August 23, 2016

Nagios Plugin for Nginx - "check_nginx_status.pl"

1. DESCRIPTION

- Plugin Name :-  check_nginx_status.pl
- Plugin Purpose :- To check NGINX Server performance stats

2. PRE-REQUISITS

- Status Page defined on Remote NGINX Server to be monitored.
- Access available to Status Page for Server where this plugin will be installed and fired from.
- Perl modules required,
use strict; use Getopt::Long; use LWP::UserAgent; use Time::HiRes qw(gettimeofday tv_interval); use Digest::MD5 qw(md5 md5_hex); use FindBin;
- Nagios Default Plugin repository is mandetory

3. PLUGIN DETAILS

- Plugin is written in Bash
- Plugin simpley checked for the node information of cassandra and checked for value of variable “Exceptions”
- Based on “Excetpions” variable value alert is thrown

4. INPUT

-H, --hostname=HOST
IP address of NGINX Server or Hostname of NGINX Server (Note:- Hostname is getting resolved from Nagios Server)
-p, --port=PORT
Http port being used by NGINX Server
-u, --url=URL
Context URL to i.e. /nginx_status instead of the default "http://<hostname or IP>/nginx_status"
-S, --ssl
Wether Remote server is using HTTPS instead of HTTP this argument is compulsary
-U, --user=user
Username for basic authentication supported on Remote NGINX Server
-P, --pass=PASS
Password for basic authentication supported on Remote NGINX Server
-r, --realm=REALM
Realm for basic authentication supported on Remote NGINX Server
-m, --maxreach=MAX
Number of max processes reached (since last check) that should trigger an alert for NGINX server
-t, --timeout=INTEGER
Timeout in seconds (Default: 15) for making connection with NGINX server
-w, --warn=ACTIVE_CONN,REQ_PER_SEC,CONN_PER_SEC
Number of active connections, ReqPerSec or ConnPerSec that will cause a WARNING if set to -1 then it means no warning
-c, --critical=ACTIVE_CONN,REQ_PER_SEC,CONN_PER_SEC
Number of active connections, ReqPerSec or ConnPerSec that will cause a CRITICAL if set to -1 then it means no CRITICAL

5. OUTPUT

Possible outputs are as below,
- “NGINX CRITICAL - 500 Can't connect to XX.XXX.XX.XX:YY (Bad hostname 'XX.XXX.XX.XX')”
Whenever plugin execution is not able to reach the specified NGINX Server i.e. XX.XXX.XX.XX for port YY

- “NGINX CRITICAL - 404 Not Found”
In case the Context URL passed to Plugin is not present on Remote NGINX server or may be miss spelled can lead to above output.

- “NGINX OK -  0.018 sec. response time, Active: 1 (Writing: 1 Reading: 0 Waiting: 0) ReqPerSec: 0.000 ConnPerSec: 0.000 ReqPerConn: 0.186|Writing=1;;;; Reading=0;;;; Waiting=0;;;; Active=1;;;; ReqPerSec=0.000000;;;; ConnPerSec=0.000000;;;; ReqPerConn=0.186081;;;;”
Post successful execution of plugin remote NGINX stats are captured in above format.

- Sample output of status page for NGINX
--------------------------------------------
Active connections: 2
server accepts handled requests
 151994 151995 50163
Reading: 0 Writing: 1 Waiting: 1
--------------------------------------------

- Capture values from the Status page as below,
Active Connection as "Active connections: 2"
Connection in waiting state as "Waiting: 1"
Connection in reading state as "Reading: 0"
Connection in writing state as "Writing: 1"
Accepted connections count as 151994
Handled connections count as 151995
Number of requests count as 50163
"Connection Per Second"= ("Last Accepted connections count" - "Current Accepted connections count")/"Difference between two checks"
"Request Per Second" = ("Last Number of Request count" - "Current Number of Request count")/"Difference between two checks";
"Request Per Connection" = ("Request Per Second")/("Connection Per Second")

6. EXAMPLE

/usr/lib64/nagios/plugins/check_nginx_status.pl -H [ IP Address/Hostname ] -p [ Port ] -u [ Context URL ] -w [ Active Connection Warning Threshold ],[Request Per Seconds Warning Threshold],[ Connection Per Seconds Warning Threshold] -c [ Active Connection Critical Threshold ],[Request Per Seconds Critical Threshold],[ Connection Per Seconds Critical Threshold]

7. Plugin can be downloaded from Link


No comments:

Post a Comment