环境:
server1 | 172.25.60.1 | server+agent |
---|---|---|
server3 | 172.25.60.3 | agent |
环境的搭建参考上一篇博客:zabbix的安装部署
确保下列服务开启:
server1:
systemctl start zabbix-server
systemctl start zabbix-agent
systemctl start httpd
systemctl start mariadb
server3:
systemctl start zabbix-agent
配置
servre3:
(1)安装nginx:
具体细节参考前面的博客:nginx的安装部署
vim auto/cc/gcc
vim src/core/nginx.h
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /sbin/
cd /usr/local/nginx/
vim conf/nginx.conf //添加以下内容
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
nging -t //语法检测
nginx //开启
(2)测试nginx
[root@server3 ~]# curl -s http://localhost/status
Active connections: 活跃的连接数
accepts: 接收到的请求数(不一定回复)
handled: 确定建立三次握手的请求数
requests: 处理的请求数
将图中的数据取出,做为监控项
curl -s http://localhost/status | grep Active | awk '{print $3}'
curl -s http://localhost/status | awk NR==3 | awk '{print $1}'
curl -s http://localhost/status | awk NR==3 | awk '{print $3}'
[root@server3 ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@server3 zabbix_agentd.d]# ls
userparameter_mysql.conf
[root@server3 zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf #将mysql服务的监控模版给nginx服务复制一份
[root@server3 zabbix_agentd.d]# vim userparameter_nginx.conf #编辑配置文件
UserParameter=nginx.active,curl -s http://localhost/status | grep Active | awk '{print $3}'
UserParameter=nginx.accepts,curl -s http://localhost/status | awk NR==3 | awk '{print $1}'
UserParameter=nginx.requests,curl -s http://localhost/status | awk NR==3 | awk '{print $3}'
##获取活跃连接数,nginx.active为健值,获得的连接数为value值
##同时获取接收到的请求数(accept)和处理的请求数(request)
[root@server3 zabbix_agentd.d]# systemctl restart zabbix-agent #修改完成重启服务。
server1:
(3)安装zabbix-get
yum install -y zabbix-get-4.0.5-1.el7.x86_64.rpm
zabbix_get 是 zabbix 服务端的一个命令,用于检测 agent 端的配置是否正确,可以很方便地知道 key 是否能正常获取到数据。
(4)在web端添加监控项
主机、server3、监控项、创建监控项
(5)添加图形
主机、server3、图形、创建图形
同样的方法添加nginx.accepts与nginx.requests
查看:
主机、server3、图形、预览
使用ab -c 1 -n 1000 http://172.25.60.3/status
增加访问