Zabbix常用監控項

u=3195662538,602835315&fm=26&gp=0.jpg


  Zabbix的大用處

Zabbix從3.0之後就多了許多自帶的監控項,比較常用的主要是CPU、內存、網卡這幾方面的監控,但是作爲一個合格的運維這遠遠的不夠的,比如一些進程的狀態,Nginx的會話情況,PHP的進程服務狀態,Redis的鍵值,數據庫的查詢情況,服務器的溫度等等這些都是我們應該時刻關注的,以爲這些都對開發有一定的幫助,假如MySQL的查詢過大多慢,那麼開發看對應的監控找出問題所在,然後進行優化處理,還有就是可以對監控項設定一定的觸發器完成自動化的操作,比如說,nginx無緣無故的掛掉了,那麼可以設置一個動作,先發一封郵件警告,然後嘗試幫你重啓服務,如果嘗試重啓不行,那麼就再發郵件通知你問題嚴重了。



  Zabbix自帶的常用項

agent.ping --- 檢測客戶端可達性。返回nothing表示不可達,1表示可達

system.cpu.load[] --- 檢測CPU 負載。返回浮點數

system.cpu.util[] --- 檢測CPU 使用率。返回浮點數

vfs.dev.read[] --- 檢測磁盤讀取數據。返回是 sps, ops, bps浮點類型,需要定義1024倍

vfs.dev.write[] --- 檢測磁盤寫入數據。返回是 sps, ops, bps浮點類型,需要定義1024倍

...

還有很多很多,但是我這裏就不一一列舉了,因爲從3.0開始Zabbix支持中文還不錯,小夥伴們可以看描述即可



  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持久化文件狀態,返回整數


  歡迎提出需求

後續如果遇到新的監控項需求,這篇博客也會更新上去,假如你有什麼想要監控的,但有不知道該怎麼監控可以在下方的評論區留言我看到後將第一時間爲你解答,就算我不會,也會有其他的小夥伴和你一起思考

當然,如果你非常關注監控運維的話,可以收藏這篇博客






待續。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章