README.md

Nginx by Zabbix agent

Overview

This template is developed to monitor Nginx by Zabbix that works without any external scripts. Most of the metrics are collected in one go, thanks to Zabbix bulk data collection.

The template Nginx by Zabbix agent - collects metrics by polling the Module ngx_http_stub_status_module locally with Zabbix agent:

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

Note that this template doesn't support HTTPS and redirects (limitations of web.page.get).

It also uses Zabbix agent to collect Nginx Linux process statistics, such as CPU usage, memory usage and whether the process is running or not.

Requirements

Zabbix version: 7.2 and higher.

Tested versions

This template has been tested on:

  • Nginx 1.17.2

Configuration

Zabbix should be configured according to the instructions in the Templates out of the box section.

Setup

See the setup instructions for ngx_http_stub_status_module. Test the availability of the http_stub_status_module nginx -V 2>&1 | grep -o with-http_stub_status_module.

Example configuration of Nginx:

location = /basic_status {
    stub_status;
    allow 127.0.0.1;
    allow ::1;
    deny all;
}

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

Example answer from Nginx:

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

Note that this template doesn't support https and redirects (limitations of web.page.get).

Install and setup Zabbix agent.

Macros used

NameDescriptionDefault
{$NGINX.STUB_STATUS.HOST}

The hostname or IP address of the Nginx host or Nginx container of astub_status.

localhost
{$NGINX.STUB_STATUS.PATH}

The path of the Nginx stub_status page.

basic_status
{$NGINX.STUB_STATUS.PORT}

The port of the Nginx stub_status host or container.

80
{$NGINX.RESPONSE_TIME.MAX.WARN}

The maximum response time of Nginx expressed in seconds for a trigger expression.

10
{$NGINX.DROP_RATE.MAX.WARN}

The critical rate of the dropped connections for a trigger expression.

1
{$NGINX.PROCESS_NAME}

The process name filter for the Nginx process discovery.

nginx
{$NGINX.PROCESS.NAME.PARAMETER}

The process name of the Nginx server used in the item key proc.get. It could be specified if the correct process name is known.

Items

NameDescriptionTypeKey and additional info
Get stub status page

The following status information is provided:

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

Accepted - the total number of accepted client connections.

Handled - the total number of handled connections. Generally, the parameter value is the same as for the accepted connections, 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 a response back to the client.

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

See also Module ngx_http_stub_status_module.

Zabbix agentweb.page.get["{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PATH}","{$NGINX.STUB_STATUS.PORT}"]
Service statusZabbix agentnet.tcp.service[http,"{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PORT}"]

Preprocessing

  • Discard unchanged with heartbeat: 10m

Service response timeZabbix agentnet.tcp.service.perf[http,"{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PORT}"]
Requests total

The total number of client requests.

Dependent itemnginx.requests.total

Preprocessing

  • Regular expression: The text is too long. Please see the template.

Requests per second

The total number of client requests.

Dependent itemnginx.requests.total.rate

Preprocessing

  • Regular expression: The text is too long. Please see the template.

  • Change per second
Connections accepted per second

The total number of accepted client connections.

Dependent itemnginx.connections.accepted.rate

Preprocessing

  • Regular expression: The text is too long. Please see the template.

  • Change per second
Connections dropped per second

The total number of dropped client connections.

Dependent itemnginx.connections.dropped.rate

Preprocessing

  • JavaScript: The text is too long. Please see the template.

  • Change per second
Connections handled per second

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

Dependent itemnginx.connections.handled.rate

Preprocessing

  • Regular expression: The text is too long. Please see the template.

  • Change per second
Connections active

The current number of active client connections including waiting connections.

Dependent itemnginx.connections.active

Preprocessing

  • Regular expression: Active connections: ([0-9]+) \1

Connections reading

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

Dependent itemnginx.connections.reading

Preprocessing

  • Regular expression: Reading: ([0-9]+) Writing: ([0-9]+) Waiting: ([0-9]+) \1

Connections waiting

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

Dependent itemnginx.connections.waiting

Preprocessing

  • Regular expression: Reading: ([0-9]+) Writing: ([0-9]+) Waiting: ([0-9]+) \3

Connections writing

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

Dependent itemnginx.connections.writing

Preprocessing

  • Regular expression: Reading: ([0-9]+) Writing: ([0-9]+) Waiting: ([0-9]+) \2

VersionDependent itemnginx.version

Preprocessing

  • Regular expression: (?i)Server: nginx\/(.+(?<!\r)) \1

  • Discard unchanged with heartbeat: 1d

Get processes summary

The aggregated data of summary metrics for all processes.

Zabbix agentproc.get[{$NGINX.PROCESS.NAME.PARAMETER},,,summary]

Triggers

NameDescriptionExpressionSeverityDependencies and additional info
Version has changed

The Nginx version has changed. Acknowledge to close the problem manually.

last(/Nginx by Zabbix agent/nginx.version,#1)<>last(/Nginx by Zabbix agent/nginx.version,#2) and length(last(/Nginx by Zabbix agent/nginx.version))>0InfoManual close: Yes

LLD rule Nginx process discovery

NameDescriptionTypeKey and additional info
Nginx process discovery

The discovery of Nginx process summary.

Dependent itemnginx.proc.discovery

Item prototypes for Nginx process discovery

NameDescriptionTypeKey and additional info
CPU utilization

The percentage of the CPU utilization by a process {#NGINX.NAME}.

Zabbix agentproc.cpu.util[{#NGINX.NAME}]
Get process data

The summary metrics aggregated by a process {#NGINX.NAME}.

Dependent itemnginx.proc.get[{#NGINX.NAME}]

Preprocessing

  • JSON Path: $.[?(@["name"]=="{#NGINX.NAME}")].first()

    ⛔️Custom on fail: Set value to: Failed to retrieve process {#NGINX.NAME} data

Memory usage (vsize)

The summary of virtual memory used by a process {#NGINX.NAME} expressed in bytes.

Dependent itemnginx.proc.vmem[{#NGINX.NAME}]

Preprocessing

  • JSON Path: $.vsize

    ⛔️Custom on fail: Discard value

Memory usage (rss)

The summary of resident set size memory used by a process {#NGINX.NAME} expressed in bytes.

Dependent itemnginx.proc.rss[{#NGINX.NAME}]

Preprocessing

  • JSON Path: $.rss

    ⛔️Custom on fail: Discard value

Memory usage, %

The percentage of real memory used by a process {#NGINX.NAME}.

Dependent itemnginx.proc.pmem[{#NGINX.NAME}]

Preprocessing

  • JSON Path: $.pmem

    ⛔️Custom on fail: Discard value

Number of running processes

The number of running processes {#NGINX.NAME}.

Dependent itemnginx.proc.num[{#NGINX.NAME}]

Preprocessing

  • JSON Path: $.processes

    ⛔️Custom on fail: Set value to: 0

  • Discard unchanged with heartbeat: 1h

Trigger prototypes for Nginx process discovery

NameDescriptionExpressionSeverityDependencies and additional info
Process is not runninglast(/Nginx by Zabbix agent/nginx.proc.num[{#NGINX.NAME}])=0High
Service is downlast(/Nginx by Zabbix agent/net.tcp.service[http,"{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PORT}"])=0 and last(/Nginx by Zabbix agent/nginx.proc.num[{#NGINX.NAME}])>0AverageManual close: Yes
High connections drop rate

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

min(/Nginx by Zabbix agent/nginx.connections.dropped.rate,5m) > {$NGINX.DROP_RATE.MAX.WARN} and last(/Nginx by Zabbix agent/nginx.proc.num[{#NGINX.NAME}])>0WarningDepends on:
  • Service is down
Service response time is too highmin(/Nginx by Zabbix agent/net.tcp.service.perf[http,"{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PORT}"],5m)>{$NGINX.RESPONSE_TIME.MAX.WARN} and last(/Nginx by Zabbix agent/nginx.proc.num[{#NGINX.NAME}])>0WarningManual close: Yes
Depends on:
  • Service is down
Failed to fetch stub status page

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

(find(/Nginx by Zabbix agent/web.page.get["{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PATH}","{$NGINX.STUB_STATUS.PORT}"],,"iregexp","HTTP\\/[\\d.]+\\s+200")=0 or nodata(/Nginx by Zabbix agent/web.page.get["{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PATH}","{$NGINX.STUB_STATUS.PORT}"],30m)) and last(/Nginx by Zabbix agent/nginx.proc.num[{#NGINX.NAME}])>0WarningManual close: Yes
Depends on:
  • 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 at ZABBIX forums

Add shortcut

Everything looks good. We'll let you know here if there's anything you should know about.