zabbix 自定义监控项 获取nginx监控状态

本篇是基于zabbix 源码安装的 

 

[root@localhost conf]# curl "http://192.168.0.73:8080/nginx_status" 
Active connections: 1 
server accepts handled requests
218 218 9326 
Reading: 0 Writing: 1 Waiting: 0

 

 

[root@localhost conf]# curl -s "http://192.168.0.73:8080/nginx_status" |grep 'Active' | awk '{print $3 } '
1

 

zabbix执行命令 获取这个1 发给server

 

1. 去zabbix安装包

 cd /soft/zabbix/zabbix-3.2.5/conf/zabbix_agentd

cp userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/

 

 

2. 修改userparameter_mysql.conf文件:

将HOME=/var/lib/zabbix全部改成HOME=/usr/local/zabbix/etc/

vim userparameter_mysql.conf

%s#HOME=/var/lib/zabbix#HOME=/usr/local/zabbix/etc/#g

 

 

3. # 修改zabbix_agentd.conf文件,添加下面一行

vim /etc/zabbix/zabbix_agentd.conf

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
 

vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf

 

 

UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/usr/local/zabbix/etc/ mysql -N'

UserParameter=mysql.ping,HOME=/usr/local/zabbix/etc/ mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

 

 

cd  /usr/local/zabbix/etc/zabbix_agentd.conf.d/

 

 

4.添加用户自定义参数

vim nginx.conf 

# 加上 UserParameter=nginx.active,/usr/bin/curl -s "http://192.168.0.73:8080/nginx_status" |grep 'Active' | awk '{print $3 } '

 

 

5.重启zabbix agnetd生效

 

6.在server端使用zabbix_get测试获取

zabbix_get 看看Key有没有生效

[root@localhost zabbix_agentd.conf.d]# zabbix_get -s localhost -p 10050 -k "nginx.active"
zabbix_get [43993]: Get value error: cannot connect to [[localhost]:10050]: [111] Connection refused

 

 

解决方法:

vim /etc/zabbix/zabbix_agentd.conf

Server=127.0.0.1 改为 server=192.168.0.73

 

 

7.在zabbix web界面创建item

 

 

添加完item 添加graph

 

再看看快速监控 监控graph

 

posted @ 2017-10-30 23:55  minger_lcm  阅读(881)  评论(0编辑  收藏  举报