zabbix密钥监控mysal、nginx、php
来源:互联网 发布:ubuntu删除搜狗输入法 编辑:程序博客网 时间:2024/06/06 03:31
一、zabbix监控mysql
在客户机上配置:
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/chk_mysql.sh
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
在后面添加:
服务端取值:
[root@iZ25t2tlsnqZ ~]# zabbix_get -s 10.44.37.221 -p10050 -k mysql.status[Com_update]
297
[root@iZ25j76vlxnZ ~]# vim /usr/local/php/etc/php-fpm.conf
[root@iZ25j76vlxnZ ~]# vim /usr/local/nginx/conf/nginx.conf
[root@iZ25j76vlxnZ ~]# service nginx restart
[root@iZ25j76vlxnZ etc]# curl -s http://localhost/status //测试是否可以看到php-fpm的状态,有信息即可
创建监控脚本:
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/chk_php-fpm.sh
引用脚本文件
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
[root@iZ25j76vlxnZ ~]# /etc/init.d/zabbix_agentd restart
[root@iZ25wrxqp21Z etc]# curl http://127.0.0.1/status
pool: www
process manager: dynamic
start time: 27/Apr/2016:14:21:33 +0800
start since: 85601
accepted conn: 37078
listen queue: 0
max listen queue: 13
listen queue len: 128
idle processes: 2
active processes: 1
total processes: 3
max active processes: 5
max children reached: 4
slow requests: 0
下面介绍每个参数的作用:
pool:php-fpm池的名称,一般都是应该是www
process manage:进程的管理方法,php-fpm支持三种管理方法,分别是static,dynamic和ondemand,一般情况下都是dynamic
start time:php-fpm启动时候的时间,不管是restart或者reload都会更新这里的时间
start since:php-fpm自启动起来经过的时间,默认为秒
accepted conn:当前接收的连接数
listen queue:在队列中等待连接的请求个数,如果这个数字为非0,那么最好增加进程的fpm个数
max listen queue:从fpm启动以来,在队列中等待连接请求的最大值
listen queue len:等待连接的套接字队列大小
idle processes:空闲的进程个数
active processes:活动的进程个数
total processes:总共的进程个数
max active processes:从fpm启动以来,活动进程的最大个数,如果这个值小于当前的max_children,可以调小此值
max children reached:当pm尝试启动更多的进程,却因为max_children的限制,没有启动更多进程的次数。如果这个值非0,那么可以适当增加fpm的进程数
slow requests:慢请求的次数,一般如果这个值未非0,那么可能会有慢的php进程,一般一个不好的mysql查询是最大的祸首。
服务器验证:
[root@iZ25t2tlsnqZ ~]# zabbix_get -s 10.44.37.221 -p 10050 -k phpfpm.status.idle.processes
127 //获取到数据说明配置没问题了,接下来在web页面上添加模板
三、监控nginx
[root@iZ25j76vlxnZ ~]# vim /usr/local/nginx/conf/nginx.conf
在php-pfm下增加:
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/chk_nginx.sh
在被监控端配置:
[liuguangshun@iZ25j76vlxnZ ~]$ vim /usr/local/zabbix/etc/zabbix_agentd.conf
在最后添加:
在被监控查看nginx状态:
[root@iZ25wrxqp21Z etc]# curl http://127.0.0.1/nginx-status
Active connections: 1
server accepts handled requests
67561 67561 159860
Reading: 0 Writing: 1 Waiting: 0
Activeconnections:对后端发起的活动连接数;
server accepts 67561:nginx 总共处理了67561个连接;
handled:成功创建了67561次握手;
requests:总共处理了159860请求。
Reading:nginx读取客户端的header数;
Writing: nginx 返回给客户端的header数;
Waiting: nginx 请求处理完成,正在等待下一请求指令的连接。
服务器上测试
[root@iZ25t2tlsnqZ ~]# zabbix_get -s 10.44.37.221 -p 10050 -k "nginx.accepts"
3151
注意:在web添加模板时,键值(密钥,web是通过键值来链接监控服务器的)要和监控端UserParameter后面的值一样,例如nginx.accepts
在客户机上配置:
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/chk_mysql.sh
#!/bin/bash# -------------------------------------------------------------------------------# FileName: check_mysql.sh# Revision: 1.0# Date: 2016/06/20# Author: Liuguangshun# Email: lgs6666@yeah.net# Website: liuguangshun.github.io# Description: # Notes: ~# -------------------------------------------------------------------------------# Copyright: 2016 (c) Liuguangshun# License: # 用户名MYSQL_USER='root'# 密码MYSQL_PWD='YyIrpFNhIofsd'# 主机地址/IPMYSQL_HOST='127.0.0.1'# 端口MYSQL_PORT='3306'# 数据连接MYSQL_CONN="/usr/local/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"# 参数是否正确if [ $# -ne "1" ];then echo "arg error!" fi# 获取数据case $1 in Uptime) result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` echo $result ;; Com_update) result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` echo $result ;; Slow_queries) result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` echo $result ;; Com_select) result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3` echo $result ;; Com_rollback) result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3` echo $result ;; Questions) result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` echo $result ;; Com_insert) result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3` echo $result ;; Com_delete) result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` echo $result ;; Com_commit) result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3` echo $result ;; Bytes_sent) result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` echo $result ;;Bytes_received) result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` echo $result ;; Com_begin) result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3` echo $result ;; *) echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" ;;Esac
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
在后面添加:
# 获取mysql版本UserParameter=mysql.version,mysql -V # 获取mysql性能指标,这个是上面定义好的脚本UserParameter=mysql.status[*],/usr/local/zabbix/etc/chk_mysql.sh $1 # 获取mysql运行状态UserParameter=mysql.ping,mysqladmin -uroot -pYyIrpFNhIofsd -P3306 -h127.0.0.1 ping | grep -c alive
服务端取值:
[root@iZ25t2tlsnqZ ~]# zabbix_get -s 10.44.37.221 -p10050 -k mysql.status[Com_update]
297
[root@iZ25j76vlxnZ ~]# vim /usr/local/php/etc/php-fpm.conf
pm.status_path = /status //把;好去掉,启用监控fpm状态
[root@iZ25j76vlxnZ ~]# vim /usr/local/nginx/conf/nginx.conf
location ~ ^/(status|ping)$ { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; allow 127.0.0.1; allow 10.170.236.125; deny all; }
[root@iZ25j76vlxnZ ~]# service nginx restart
[root@iZ25j76vlxnZ etc]# curl -s http://localhost/status //测试是否可以看到php-fpm的状态,有信息即可
创建监控脚本:
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/chk_php-fpm.sh
#!/bin/bash#monitor php-fpm status from zabbix#lincense:GPL#mail:lgs6666@yeah.net#date:2016.06.20source /etc/bashrc >/dev/null 2>&1source /etc/profile >/dev/null 2>&1LOG=/usr/local/zabbix/etc/phpfpm_status.logcurl -s http://localhost/status >$LOGpool(){ awk '/pool/ {print $NF}' $LOG}process_manager(){ awk '/process manager/ {print $NF}' $LOG}start_since(){ awk '/start since:/ {print $NF}' $LOG}accepted_conn(){ awk '/accepted conn:/ {print $NF}' $LOG}listen_queue(){ awk '/^(listen queue:)/ {print $NF}' $LOG}max_listen_queue(){ awk '/max listen queue:/ {print $NF}' $LOG}listen_queue_len(){ awk '/listen queue len:/ {print $NF}' $LOG}idle_processes(){ awk '/idle processes:/ {print $NF}' $LOG}active_processes(){ awk '/^(active processes:)/ {print $NF}' $LOG}total_processes(){ awk '/total processes:/ {print $NF}' $LOG}max_active_processes(){ awk '/max active processes:/ {print $NF}' $LOG}max_children_reached(){ awk '/max children reached:/ {print $NF}' $LOG}slow_requests(){ awk '/slow requests:/ {print $NF}' $LOG}case "$1" inpool) pool ;;process_manager) process_manager ;;start_since) start_since ;;accepted_conn) accepted_conn ;;listen_queue) listen_queue ;;max_listen_queue) max_listen_queue ;;listen_queue_len) listen_queue_len ;;idle_processes) idle_processes ;;active_processes) active_processes ;;total_processes) total_processes ;;max_active_processes) max_active_processes ;;max_children_reached) max_children_reached ;;slow_requests) slow_requests ;;*)echo "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached|slow_requests}"esac
引用脚本文件
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
#UserParameter=php-fpm[*],/usr/local/zabbix/etc/chk_php-fpm.sh "$1"UserParameter=phpfpm.status.pool,/usr/local/zabbix/etc/chk_php-fpm.sh poolUserParameter=phpfpm.status.process.manager,/usr/local/zabbix/etc/chk_php-fpm.sh process_managerUserParameter=phpfpm.status.start.since,/usr/local/zabbix/etc/chk_php-fpm.sh start_sinceUserParameter=phpfpm.status.accepted.conn,/usr/local/zabbix/etc/chk_php-fpm.sh accepted_connUserParameter=phpfpm.status.listen.queue,/usr/local/zabbix/etc/chk_php-fpm.sh listen_queueUserParameter=phpfpm.status.max.listen.queue,/usr/local/zabbix/etc/chk_php-fpm.sh max_listen_queueUserParameter=phpfpm.status.listen.queue.len,/usr/local/zabbix/etc/chk_php-fpm.sh listen_queue_lenUserParameter=phpfpm.status.idle.processes,/usr/local/zabbix/etc/chk_php-fpm.sh idle_processesUserParameter=phpfpm.status.active.processes,/usr/local/zabbix/etc/chk_php-fpm.sh active_processesUserParameter=phpfpm.status.total.processes,/usr/local/zabbix/etc/chk_php-fpm.sh total_processesUserParameter=phpfpm.status.max.active.processes,/usr/local/zabbix/etc/chk_php-fpm.sh max_active_processesUserParameter=phpfpm.status.max.children.reached,/usr/local/zabbix/etc/chk_php-fpm.sh max_children_reachedUserParameter=phpfpm.status.slow.requests,/usr/local/zabbix/etc/chk_php-fpm.sh slow_requests
[root@iZ25j76vlxnZ ~]# /etc/init.d/zabbix_agentd restart
[root@iZ25wrxqp21Z etc]# curl http://127.0.0.1/status
pool: www
process manager: dynamic
start time: 27/Apr/2016:14:21:33 +0800
start since: 85601
accepted conn: 37078
listen queue: 0
max listen queue: 13
listen queue len: 128
idle processes: 2
active processes: 1
total processes: 3
max active processes: 5
max children reached: 4
slow requests: 0
下面介绍每个参数的作用:
pool:php-fpm池的名称,一般都是应该是www
process manage:进程的管理方法,php-fpm支持三种管理方法,分别是static,dynamic和ondemand,一般情况下都是dynamic
start time:php-fpm启动时候的时间,不管是restart或者reload都会更新这里的时间
start since:php-fpm自启动起来经过的时间,默认为秒
accepted conn:当前接收的连接数
listen queue:在队列中等待连接的请求个数,如果这个数字为非0,那么最好增加进程的fpm个数
max listen queue:从fpm启动以来,在队列中等待连接请求的最大值
listen queue len:等待连接的套接字队列大小
idle processes:空闲的进程个数
active processes:活动的进程个数
total processes:总共的进程个数
max active processes:从fpm启动以来,活动进程的最大个数,如果这个值小于当前的max_children,可以调小此值
max children reached:当pm尝试启动更多的进程,却因为max_children的限制,没有启动更多进程的次数。如果这个值非0,那么可以适当增加fpm的进程数
slow requests:慢请求的次数,一般如果这个值未非0,那么可能会有慢的php进程,一般一个不好的mysql查询是最大的祸首。
服务器验证:
[root@iZ25t2tlsnqZ ~]# zabbix_get -s 10.44.37.221 -p 10050 -k phpfpm.status.idle.processes
127 //获取到数据说明配置没问题了,接下来在web页面上添加模板
三、监控nginx
[root@iZ25j76vlxnZ ~]# vim /usr/local/nginx/conf/nginx.conf
在php-pfm下增加:
location /nginx-status { stub_status on; access_log on; allow 127.0.0.1; allow 10.170.236.125; deny all; }
[root@iZ25j76vlxnZ ~]# vim /usr/local/zabbix/etc/chk_nginx.sh
#!/bin/bash# Script to fetch nginx statuses for tribily monitoring systems# Author: lgs6666@yeah.net# License: GPLv2# Set VariablesBKUP_DATE=`/bin/date +%Y%m%d`LOG="/data/log/zabbix/webstatus.log"HOST=127.0.0.1PORT="80"# Functions to return nginx statsfunction active {/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Active' | awk '{print $NF}'}function reading {/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Reading' | awk '{print $2}'}function writing {/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Writing' | awk '{print $4}'}function waiting {/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'}function accepts {/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $1}'}function handled {/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $2}'}function requests {/usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $3}'}# Run the requested function$1
在被监控端配置:
[liuguangshun@iZ25j76vlxnZ ~]$ vim /usr/local/zabbix/etc/zabbix_agentd.conf
在最后添加:
UserParameter=nginx.accepts,/usr/local/zabbix/etc/chk_nginx.sh acceptsUserParameter=nginx.handled,/usr/local/zabbix/etc/chk_nginx.sh handledUserParameter=nginx.requests,/usr/local/zabbix/etc/chk_nginx.sh requestsUserParameter=nginx.connections.active,/usr/local/zabbix/etc/chk_nginx.sh activeUserParameter=nginx.connections.reading,/usr/local/zabbix/etc/chk_nginx.sh readingUserParameter=nginx.connections.writing,/usr/local/zabbix/etc/chk_nginx.sh writingUserParameter=nginx.connections.waiting,/usr/local/zabbix/etc/chk_nginx.sh waiting
在被监控查看nginx状态:
[root@iZ25wrxqp21Z etc]# curl http://127.0.0.1/nginx-status
Active connections: 1
server accepts handled requests
67561 67561 159860
Reading: 0 Writing: 1 Waiting: 0
Activeconnections:对后端发起的活动连接数;
server accepts 67561:nginx 总共处理了67561个连接;
handled:成功创建了67561次握手;
requests:总共处理了159860请求。
Reading:nginx读取客户端的header数;
Writing: nginx 返回给客户端的header数;
Waiting: nginx 请求处理完成,正在等待下一请求指令的连接。
服务器上测试
[root@iZ25t2tlsnqZ ~]# zabbix_get -s 10.44.37.221 -p 10050 -k "nginx.accepts"
3151
注意:在web添加模板时,键值(密钥,web是通过键值来链接监控服务器的)要和监控端UserParameter后面的值一样,例如nginx.accepts
阅读全文
0 0
- zabbix密钥监控mysal、nginx、php
- zabbix监控nginx、php参考
- zabbix监控nginx、php-fpm的状态
- zabbix监控nginx、php-fpm的状态
- 利用Zabbix监控Nginx
- 利用Zabbix监控Nginx
- Zabbix 监控 Nginx
- Zabbix监控nginx性能
- zabbix监控 nginx 模板
- zabbix 监控 nginx
- Zabbix监控nginx性能
- zabbix监控Nginx状态
- zabbix 监控nginx
- [Zabbix] Nginx 监控
- zabbix 3.0 nginx监控
- Zabbix监控nginx性能
- zabbix监控Nginx
- zabbix监控nginx状态
- Coursera | Andrew Ng (01-week-1-1.1)—Introduction to Deep Learning
- 去掉HTML中的部分正文内容
- FileSizeLimitExceededException的maximum permitted size of 1048576 bytes问题
- 版本号命名规则
- 获取window系统版本GetVersionEx
- zabbix密钥监控mysal、nginx、php
- Python基础篇之列表生成式
- android md5求hash值
- 使用python socket多线程实现大文件分发
- 【转载】Makefile经典教程
- 百度ai—细粒度图像识别
- 安装MySQL解压版
- EBS与外来项目系统对接接口BOM AND ECN interface coding
- mysql 搜寻附近N公里内数据的实例