Nginx

Nginx

Available solutions




Source: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/app/nginx_http


Template App Nginx by HTTP

Overview

For Zabbix version: 4.4
The template to monitor Nginx by Zabbix that work without any external scripts. Most of the metrics are collected in one go, thanks to Zabbix bulk data collection.

Template App Nginx by HTTP collects metrics by polling ngx_http_stub_status_module with HTTP agent remotely:

Active connections: 291 
server accepts handled requests
16630948 16630948 31070465 
Reading: 6 Writing: 179 Waiting: 106 

Note that this solution supports https and redirects.

This template was tested on:

  • Nginx, version 1.17.2

Setup

Setup ngx_http_stub_status_module. Test availability of http_stub_status module with nginx -V 2>&1 | grep -o with-http_stub_status_module.

Example configuration of Nginx:

location = /basic_status {
    stub_status;
    allow <IP of your Zabbix server/proxy>;
    deny all;
}

If you use another location, don't forget to change {$NGINX.STUB_STATUS.PATH} macro.

Zabbix configuration

No specific Zabbix configuration is required.

Macros used

NameDescriptionDefault
{$NGINX.DROP_RATE.MAX.WARN}

The critical rate of the dropped connections for trigger expression.

1
{$NGINX.RESPONSE_TIME.MAX.WARN}

The Nginx maximum response time in seconds for trigger expression.

10
{$NGINX.STUB_STATUS.PATH}

The path of Nginx stub_status page.

basic_status
{$NGINX.STUB_STATUS.PORT}

The port of Nginx stub_status host or container.

80
{$NGINX.STUB_STATUS.SCHEME}

The protocol http or https of Nginx stub_status host or container.

http

Template links

There are no template links in this template.

Discovery rules

Items collected

GroupNameDescriptionTypeKey and additional info
NginxNginx: Service status

-

SIMPLEnet.tcp.service[http,"{HOST.CONN}","{$NGINX.STUB_STATUS.PORT}"]

Preprocessing:

- DISCARD_UNCHANGED_HEARTBEAT: 10m

NginxNginx: Service response time

-

SIMPLEnet.tcp.service.perf[http,"{HOST.CONN}","{$NGINX.STUB_STATUS.PORT}"]
NginxNginx: Requests total

The total number of client requests.

DEPENDENTnginx.requests.total

Preprocessing:

- REGEX: server accepts handled requests\s+([0-9]+) ([0-9]+) ([0-9]+) \3

NginxNginx: Requests per second

The total number of client requests.

DEPENDENTnginx.requests.total.rate

Preprocessing:

- REGEX: server accepts handled requests\s+([0-9]+) ([0-9]+) ([0-9]+) \3

- CHANGE_PER_SECOND

NginxNginx: Connections accepted per second

The total number of accepted client connections.

DEPENDENTnginx.connections.accepted.rate

Preprocessing:

- REGEX: server accepts handled requests\s+([0-9]+) ([0-9]+) ([0-9]+) \1

- CHANGE_PER_SECOND

NginxNginx: Connections dropped per second

The total number of dropped client connections.

DEPENDENTnginx.connections.dropped.rate

Preprocessing:

- JAVASCRIPT: var a = value.match(/server accepts handled requests\s+([0-9]+) ([0-9]+) ([0-9]+)/) if (a) { return a[1]-a[2] }

- CHANGE_PER_SECOND

NginxNginx: Connections handled per second

The total number of handled connections. Generally, the parameter value is the same as accepts unless some resource limits have been reached (for example, the worker_connections limit).

DEPENDENTnginx.connections.handled.rate

Preprocessing:

- REGEX: server accepts handled requests\s+([0-9]+) ([0-9]+) ([0-9]+) \2

- CHANGE_PER_SECOND

NginxNginx: Connections active

The current number of active client connections including Waiting connections.

DEPENDENTnginx.connections.active

Preprocessing:

- REGEX: Active connections: ([0-9]+) \1

NginxNginx: Connections reading

The current number of connections where nginx is reading the request header.

DEPENDENTnginx.connections.reading

Preprocessing:

- REGEX: Reading: ([0-9]+) Writing: ([0-9]+) Waiting: ([0-9]+) \1

NginxNginx: Connections waiting

The current number of idle client connections waiting for a request.

DEPENDENTnginx.connections.waiting

Preprocessing:

- REGEX: Reading: ([0-9]+) Writing: ([0-9]+) Waiting: ([0-9]+) \3

NginxNginx: Connections writing

The current number of connections where nginx is writing the response back to the client.

DEPENDENTnginx.connections.writing

Preprocessing:

- REGEX: Reading: ([0-9]+) Writing: ([0-9]+) Waiting: ([0-9]+) \2

NginxNginx: Version

-

DEPENDENTnginx.version

Preprocessing:

- REGEX: Server: nginx/(.+) \1

- DISCARD_UNCHANGED_HEARTBEAT: 1d

Zabbix_raw_itemsNginx: Get stub status page

The following status information is provided:

Active connections - the current number of active client connections including Waiting connections.

Accepts - the total number of accepted client connections.

Handled - the total number of handled connections. Generally, the parameter value is the same as accepts unless some resource limits have been reached (for example, the worker_connections limit).

Requests - the total number of client requests.

Reading - the current number of connections where nginx is reading the request header.

Writing - the current number of connections where nginx is writing the response back to the client.

Waiting - the current number of idle client connections waiting for a request.

https://nginx.org/en/docs/http/ngx_http_stub_status_module.html

HTTP_AGENTnginx.get_stub_status

Triggers

NameDescriptionExpressionSeverityDependencies and additional info
Nginx: Service is down

-

{TEMPLATE_NAME:net.tcp.service[http,"{HOST.CONN}","{$NGINX.STUB_STATUS.PORT}"].last()}=0AVERAGE

Manual close: YES

Nginx: Service response time is too high (over {$NGINX.RESPONSE_TIME.MAX.WARN}s for 5m)

-

{TEMPLATE_NAME:net.tcp.service.perf[http,"{HOST.CONN}","{$NGINX.STUB_STATUS.PORT}"].min(5m)}>{$NGINX.RESPONSE_TIME.MAX.WARN}WARNING

Manual close: YES

Depends on:

- Nginx: Service is down

Nginx: High connections drop rate (more than {$NGINX.DROP_RATE.MAX.WARN} for 5m)

The dropping rate connections is greater than {$NGINX.DROP_RATE.MAX.WARN} for the last 5 minutes.

{TEMPLATE_NAME:nginx.connections.dropped.rate.min(5m)} > {$NGINX.DROP_RATE.MAX.WARN}WARNING

Depends on:

- Nginx: Service is down

Nginx: Version has changed (new version: {ITEM.VALUE})

Nginx version has changed. Ack to close.

{TEMPLATE_NAME:nginx.version.diff()}=1 and {TEMPLATE_NAME:nginx.version.strlen()}>0INFO

Manual close: YES

Nginx: Failed to fetch stub status page (or no data for 30m)

Zabbix has not received data for items for the last 30 minutes.

{TEMPLATE_NAME:nginx.get_stub_status.str("HTTP/1.1 200")}=0 or {TEMPLATE_NAME:nginx.get_stub_status.nodata(30m)}=1WARNING

Manual close: YES

Depends on:

- Nginx: Service is down

Feedback

Please report any issues with the template at https://support.zabbix.com

You can also provide feedback, discuss the template or ask for help with it at ZABBIX forums.

Articles and documentation

+ Propose new article
Add your solution