Zabbix的大用處php
Zabbix從3.0以後就多了許多自帶的監控項,比較經常使用的主要是CPU、內存、網卡這幾方面的監控,可是做爲一個合格的運維這遠遠的不夠的,好比一些進程的狀態,Nginx的會話狀況,PHP的進程服務狀態,Redis的鍵值,數據庫的查詢狀況,服務器的溫度等等這些都是咱們應該時刻關注的,覺得這些都對開發有必定的幫助,假如MySQL的查詢過大多慢,那麼開發看對應的監控找出問題所在,而後進行優化處理,還有就是能夠對監控項設定必定的觸發器完成自動化的操做,好比說,nginx平白無故的掛掉了,那麼能夠設置一個動做,先發一封郵件警告,而後嘗試幫你重啓服務,若是嘗試重啓不行,那麼就再發郵件通知你問題嚴重了。
nginx
Zabbix自帶的經常使用項redis
agent.ping --- 檢測客戶端可達性。返回nothing表示不可達,1表示可達數據庫
system.cpu.load[] --- 檢測CPU 負載。返回浮點數
vim
system.cpu.util[] --- 檢測CPU 使用率。返回浮點數緩存
vfs.dev.read[] --- 檢測磁盤讀取數據。返回是 sps, ops, bps浮點類型,須要定義1024倍bash
vfs.dev.write[] --- 檢測磁盤寫入數據。返回是 sps, ops, bps浮點類型,須要定義1024倍服務器
...
運維
還有不少不少,可是我這裏就不一一列舉了,由於從3.0開始Zabbix支持中文還不錯,小夥伴們能夠看描述便可curl
Zabbix的自定義經常使用項
內存相關的自定義項
vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/catram.conf UserParameter=ram.info[*],/bin/cat /proc/meminfo | awk '/^$1:/{print $$2}'
ram.info[Cached] --- 檢測內存的緩存使用量,返回整數,須要定義1024倍
ram.info[MemFree] --- 檢測內存的空餘量,返回整數,須要定義1024倍
ram.info[Buffers] --- 檢測內存的使用量,返回整數,須要定義1024倍
TCP相關的自定義項
vim /usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh #!/bin/bash function ESTAB { /usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'ESTAB' | awk '{print $2}' } function TIMEWAIT { /usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'TIME-WAIT' | awk '{print $2}' } function LISTEN { /usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'LISTEN' | awk '{print $2}' } $1 vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/cattcp.conf UserParameter=tcp[*],/usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh $1
tcp[TIMEWAIT] --- 檢測TCP的駐留數,返回整數
tcp[ESTAB] --- 檢測TCP的鏈接數,返回整數
tcp[LISTEN] --- 檢測TCP的監聽數,返回整數
Nginx相關的自定義項
vim /etc/nginx/conf.d/default.conf location /nginx-status { stub_status on; access_log off; allow 127.0.0.1; deny all; } vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf UserParameter=Nginx.active,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/Active/ {print $NF}' UserParameter=Nginx.read,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | grep 'Reading' | cut -d" " -f2 UserParameter=Nginx.wrie,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | grep 'Writing' | cut -d" " -f4 UserParameter=Nginx.wait,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | grep 'Waiting' | cut -d" " -f6 UserParameter=Nginx.accepted,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $1}' UserParameter=Nginx.handled,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $2}' UserParameter=Nginx.requests,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $3}'
Nginx.active --- 檢測Nginx正處理鏈接數,返回整數
Nginx.read --- 檢測Nginx讀取信息數,返回整數
Nginx.wrie --- 檢測Nginx返回信息數,返回整數
Nginx.wait --- 檢測Nginx駐留鏈接數,返回整數
Nginx.accepted --- 檢測Nginx已處理鏈接數,返回整數
Nginx.handled --- 檢測Nginx成功握手數,返回整數
Nginx.requests --- 檢測Nginx成功請求數,返回整數
PHP相關的自定義項
vim /etc/nginx/conf.d/default.conf location /status { allow 127.0.0.1; deny all; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; include fastcgi_params; fastcgi_pass unix:/dev/shm/php5-fpm.sock; } vi /etc/php-fpm.d/www.conf pm.status_path = /status vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/php.conf UserParameter=PHP.listenqueue,/usr/bin/wget --quiet -O - http://127.0.0.1:80/status?auto | grep "listen queue:" | grep -vE "len|max" | awk '{print $3}' UserParameter=PHP.idle,wget --quiet -O - http://127.0.0.1:80/status?auto | grep "idle processes" | awk '{print $3}' UserParameter=PHP.active,wget --quiet -O - http://127.0.0.1:80/status?auto | grep "active" | awk '{print $3}'| grep -v "process" UserParameter=PHP.conn,wget --quiet -O - http://127.0.0.1:80/status?auto | grep "accepted conn" | awk '{print $3}' UserParameter=PHP.reached,wget --quiet -O - http://127.0.0.1:80/status?auto | grep "max children reached" | awk '{print $4}' UserParameter=PHP.requests,wget --quiet -O - http://127.0.0.1:80/status?auto | grep "slow requests" | awk '{print $3}'
PHP.listenqueue --- 檢測PHP隊列數,返回整數
PHP.idle --- 檢測PHP空閒進程數,返回整數
PHP.active --- 檢測PHP活動進程數,返回整數
PHP.conn --- 檢測PHP請求數,返回整數
PHP.reached --- 檢測PHP達到限制次數,返回整數
PHP.requests --- 檢測PHP慢請求數,返回整數
Redis相關的自定義項
vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/redis.conf UserParameter=Redis.Status,/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 ping |grep -c PONG UserParameter=Redis_conn[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "connected_clients" | awk -F':' '{print $2}' UserParameter=Redis_rss_mem[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_memory_rss" | awk -F':' '{print $2}' UserParameter=Redis_lua_mem[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_memory_lua" | awk -F':' '{print $2}' UserParameter=Redis_cpu_sys[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_sys" | awk -F':' '{print $2}' UserParameter=Redis_cpu_user[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_user" | awk -F':' '{print $2}' UserParameter=Redis_cpu_sys_cline[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_sys_children" | awk -F':' '{print $2}' UserParameter=Redis_cpu_user_cline[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_user_children" | awk -F':' '{print $2}' UserParameter=Redis_keys_num[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "$$1" | grep -w "keys" | grep db$3 | awk -F'=' '{print $2}' | awk -F',' '{print $1}' UserParameter=Redis_loading[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep loading | awk -F':' '{print $$2}'
Redis.Status --- 檢測Redis運行狀態,返回整數
Redis_conn --- 檢測Redis成功鏈接數,返回整數
Redis_rss_mem --- 檢測Redis系統分配內存,返回整數
Redis_lua_mem --- 檢測Redis引擎消耗內存,返回整數
Redis_cpu_sys --- 檢測Redis主程序核心CPU消耗率,返回整數
Redis_cpu_user --- 檢測Redis主程序用戶CPU消耗率,返回整數
Redis_cpu_sys_cline --- 檢測Redis後臺核心CPU消耗率,返回整數
Redis_cpu_user_cline --- 檢測Redis後臺用戶CPU消耗率,返回整數
Redis_keys_num --- 檢測庫鍵值數,返回整數
Redis_loading --- 檢測Redis持久化文件狀態,返回整數
歡迎提出需求
後續若是遇到新的監控項需求,這篇博客也會更新上去,假如你有什麼想要監控的,但有不知道該怎麼監控能夠在下方的評論區留言我看到後將第一時間爲你解答,就算我不會,也會有其餘的小夥伴和你一塊兒思考
固然,若是你很是關注監控運維的話,能夠收藏這篇博客
待續。。。