zabbix 模板配置Nginx 监控

实际操作:

1 检查nginx是否开启了--with-http_stub_status_module。

[root@nginx sbin]# ./nginx -V

nginx version: nginx/1.18.0

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

built with OpenSSL 1.0.2k-fips 26 Jan 2017

TLS SNI support enabled

configure arguments: --prefix=/bea/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_realip_module

2 检查nginx配置,主要检查是否配置了状态检查的路径,以及对应可以访问的IP.(因zabbix是通过agent去监控,所以只需要allow 127.0.0.1 即可)

location = /basic_status {

stub_status;

allow 127.0.0.1;

allow ::1;

deny all;

}

3 在zabbix监控web界面上,主机监控添加nginx的模板

4 如果nginx.conf的端口,以及相对路径(basic_status)进行了修改,我们可以通过修改该主机的监控的宏来修改。

5 监控效果

Nginx by Zabbix agent

Overview

For Zabbix version: 5.4 and higher

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 Nginx by Zabbix agent collects metrics by polling 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 stats like CPU usage, memory usage and whether process is running or not.

This template was tested on:

  • Nginx, version 1.17.2

Setup

See Zabbix template operation for basic instructions.

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 127.0.0.1; allow ::1; deny all; }

If you use another location, then don't forget to change {$NGINX.STUB_STATUS.PATH} macro. Install and setup Zabbix agent.

Zabbix configuration

No specific Zabbix configuration is required.

Macros used

Name

Description

Default

{$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.HOST}

Hostname or IP of Nginx stub_status host or container.

localhost

{$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

Template links

There are no template links in this template.

Discovery rules

Items collected

Group

Name

Description

Type

Key and additional info

Nginx

Nginx: Service status

-

ZABBIX_PASSIVE

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

Preprocessing:

- DISCARD_UNCHANGED_HEARTBEAT: 10m

Nginx

Nginx: Service response time

-

ZABBIX_PASSIVE

net.tcp.service.perf[http,"{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PORT}"]

Nginx

Nginx: Requests total

The total number of client requests.

DEPENDENT

nginx.requests.total

Preprocessing:

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

Nginx

Nginx: Requests per second

The total number of client requests.

DEPENDENT

nginx.requests.total.rate

Preprocessing:

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

- CHANGE_PER_SECOND

Nginx

Nginx: Connections accepted per second

The total number of accepted client connections.

DEPENDENT

nginx.connections.accepted.rate

Preprocessing:

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

- CHANGE_PER_SECOND

Nginx

Nginx: Connections dropped per second

The total number of dropped client connections.

DEPENDENT

nginx.connections.dropped.rate

Preprocessing:

- JAVASCRIPT: Text is too long. Please see the template.

- CHANGE_PER_SECOND

Nginx

Nginx: 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).

DEPENDENT

nginx.connections.handled.rate

Preprocessing:

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

- CHANGE_PER_SECOND

Nginx

Nginx: Connections active

The current number of active client connections including Waiting connections.

DEPENDENT

nginx.connections.active

Preprocessing:

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

Nginx

Nginx: Connections reading

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

DEPENDENT

nginx.connections.reading

Preprocessing:

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

Nginx

Nginx: Connections waiting

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

DEPENDENT

nginx.connections.waiting

Preprocessing:

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

Nginx

Nginx: Connections writing

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

DEPENDENT

nginx.connections.writing

Preprocessing:

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

Nginx

Nginx: Number of processes running

Number of the Nginx processes running.

ZABBIX_PASSIVE

proc.num[nginx]

Nginx

Nginx: Memory usage (vsize)

Virtual memory size used by process in bytes.

ZABBIX_PASSIVE

proc.mem[nginx,,,,vsize]

Nginx

Nginx: Memory usage (rss)

Resident set size memory used by process in bytes.

ZABBIX_PASSIVE

proc.mem[nginx,,,,rss]

Nginx

Nginx: CPU utilization

Process CPU utilization percentage.

ZABBIX_PASSIVE

proc.cpu.util[nginx]

Nginx

Nginx: Version

-

DEPENDENT

nginx.version

Preprocessing:

- REGEX: Server: nginx\/(.+(?

- DISCARD_UNCHANGED_HEARTBEAT: 1d

Zabbix_raw_items

Nginx: 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

ZABBIX_PASSIVE

web.page.get["{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PATH}","{$NGINX.STUB_STATUS.PORT}"]

Triggers

Name

Description

Expression

Severity

Dependencies and additional info

Nginx: Service is down

-

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

AVERAGE

Manual close: YES

Depends on:

- Nginx: Process is not running

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

-

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

WARNING

Manual close: YES

Depends on:

- Nginx: Process is not running

- 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: Process is not running

- Nginx: Service is down

Nginx: Process is not running

-

{TEMPLATE_NAME:proc.num[nginx].last()}=0

HIGH

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()}>0

INFO

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:web.page.get["{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PATH}","{$NGINX.STUB_STATUS.PORT}"].str("HTTP/1.1 200")}=0 or {TEMPLATE_NAME:web.page.get["{$NGINX.STUB_STATUS.HOST}","{$NGINX.STUB_STATUS.PATH}","{$NGINX.STUB_STATUS.PORT}"].nodata(30m)}=1

WARNING

Manual close: YES

Depends on:

- Nginx: Process is not running

- Nginx: Service is down

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值