zabbix监控nginx性能
NGINX worker 进程接受 OS 的连接请求时 Accepts 计数器增加,而Handled 是当实际的请求得到连接时(通过建立一个新的连接或重新使用一个空闲的)。这两个计数器的值通常都是相同的,如果它们有差别则表明连接被Dropped, 往往这是由于资源限制,比如已经达到 NGINX 的worker_connections的限制。
首先nginx需要配置nginx_status 具体步骤是:在 zabbix agentd客户端上,查看nginx是否加载了with-http_stub_status_module。因为 zabbix 监控nginx是根据nginx的Stub Status模块,抓取Status模块所提供的数据。假如以前没开启,现在想启用StubStatus 模块,在编译nginx 的时候要加上参数with-http_stub_status_module,执行./configure && make就可以了,不用make install,一般情况下都是安装的,具体的安装配置如下
实验环境:
server1 server端
server2 agent
先将server端,agent端安装好,在此不再赘述
agent端:
安装nginx
[root@server2 mnt]# ls
nginx-1.8.0-1.el6.ngx.x86_64.rpm
[root@server2 mnt]# rpm -ivh nginx-1.8.0-1.el6.ngx.x86_64.rpm
warning: nginx-1.8.0-1.el6.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing... ########################################### [100%]
1:nginx ########################################### [100%]
配置nginxstatus
[root@server2 mnt]# cd /etc/nginx/
[root@server2 nginx]# cd conf.d/
[root@server2 conf.d]# ls
default.conf example_ssl.conf
[root@server2 conf.d]# vim default.conf
打开status, 关闭日志 ,接受自己,拒绝所有
打开nginx
[root@server2 conf.d]# nginx
测试:
[aaa@qq.com conf.d]# curl http://172.25.24.2/status ##被拒绝
<html>
<head><title>403 Forbidden</title></head> ##403为拒绝访问
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>
[aaa@qq.com conf.d]# curl http://127.0.0.1/status
Active connections: 1 ##活跃的数量
server accepts handled requests
3 3 28
Reading: 0 Writing: 1 Waiting: 0
server accept(接受的数量) handled(已处理数量)requests(求情数量)
在server-agent中添加nginx的status文件
Agentd安装在被监控的主机上,Agent负责定期收集客户端本地各项数据,并发送至Zabbix Server端,Zabbix Server收到数据,将数据存储到数据库中,用户基于Zabbix WEB可以看到数据在前端展现图像。当Zabbix监控某个具体的项目,改项目会设置一个触发器阈值,当被监控的指标超过该触发器设定的阈值,会进行一些必要的动作,动作包括:发送信息(邮件、微信、短信)、发送命令(SHELL 命令、Reboot、Restart、Install等)。
[aaa@qq.com conf.d]# cd /etc/zabbix/
[aaa@qq.com zabbix]# cd zabbix_agentd.d/
[aaa@qq.com zabbix_agentd.d]# ls
userparameter_mysql.conf
[aaa@qq.com zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf
[aaa@qq.com zabbix_agentd.d]# ls
userparameter_mysql.conf userparameter_nginx.conf
[root@server2 zabbix_agentd.d]# vim userparameter_nginx.conf
文件内容演示:
[aaa@qq.com conf.d]# curl http://127.0.0.1/status
Active connections: 1
server accepts handled requests
3 3 28
Reading: 0 Writing: 1 Waiting: 0
通过awk命令可以截取出来Active connections
server accepts
server handled
server requests
[root@server2 conf.d]# curl -s http://127.0.0.1/status |grep Active | awk '{print $NF}'
1
[root@server2 zabbix_agentd.d]# curl -s http://127.0.0.1/status |awk NR==3 |awk '{print $3}'
53
[root@server2 zabbix_agentd.d]# curl -s http://127.0.0.1/status |awk NR==3 |awk '{print $1}'
15
[root@server2 zabbix_agentd.d]# curl -s http://127.0.0.1/status |awk NR==3 |awk '{print $2}'
启动zabbix-agent
[root@server2 zabbix_agentd.d]# chkconfig zabbix-agent on ##开机自启
[root@server2 zabbix_agentd.d]# /etc/init.d/zabbix-agent start
Starting Zabbix agent: [ OK ]
server端:
启动zabbix-server 、zabbix-agent 、mariadb
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl start zabbix-server
[root@localhost ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@localhost ~]# systemctl start zabbix-agent
[root@localhost ~]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
安装zabbix-get
[root@localhost ~]# rpm -ivh zabbix-get-3.4.6-1.el7.x86_64.rpm
warning: zabbix-get-3.4.6-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-get-3.4.6-1.el7 ################################# [100%]
测试取值:
[root@localhost ~]# zabbix_get -s 172.25.24.2 -p 10050 -k 'nginx.active' ##取值
1
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# zabbix_get -s 172.25.24.2 -p 10050 -k 'nginx.active1'
ZBX_NOTSUPPORTED: Unsupported item key.
[root@localhost ~]# zabbix_get -s 172.25.24.2 -p 10050 -k 'nginx.active2'
ZBX_NOTSUPPORTED: Unsupported item key.
[root@localhost ~]# zabbix_get -s 172.25.24.2 -p 10050 -k 'nginx.active2'
17
[root@localhost ~]# zabbix_get -s 172.25.24.2 -p 10050 -k 'nginx.active2'
18
浏览器添加:
添加的四个监控项与上面agent端添加的nginx status配置需要一一对应
创建监控图表
将监控项目添加到图表中
图表展示:
上一篇: zabbix监控nginx