linux上zabbix監(jiān)控網(wǎng)站诚隙,站點(diǎn)訪問量(每秒枢赔,分,時(shí),天)
zabbix-agent客戶端操作
1:自定義監(jiān)控項(xiàng)
vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
以baidu當(dāng)做站點(diǎn)名稱舉例
baidu網(wǎng)站站點(diǎn)web今日所有訪問量:
UserParameter=baidu.d,A=`date | awk '{print $3,$2,$6}' | sed 's# #/#g'`;cat /var/log/nginx/baidu/web.access.log | grep "$A" | wc -l
baidu站點(diǎn)web每小時(shí)的訪問量:
UserParameter=baidu.h,A=`date | awk '{print $3,$2,$6}' | sed 's# #/#g'`;B=`date | awk '{print $4}' | awk -F":" '{print $1}'`;cat /var/log/nginx/baidu/web.access.log | grep "$A":"$B" | wc -l
baidu站點(diǎn)web每分鐘的訪問量
UserParameter=baidu.m,A=`date | awk '{print $3,$2,$6}' | sed 's# #/#g'`;B=`date | awk '{print $4}' | awk -F":" '{print $1,$2}' | sed 's# #:#g'`;cat /var/log/nginx/baidu/web.access.log | grep "$A":"$B" | wc -l
baidu站點(diǎn)web每秒訪問量
UserParameter=baidu.s,A=`date | awk '{print $3,$2,$6}' | sed 's# #/#g'`;B=`date | awk '{print $4}' | awk -F":" '{print $1,$2,$3}' | sed 's# #:#g'`;cat /var/log/nginx/baidu/web.access.log | grep "$A":"$B" | wc -l
說明:
grep "$A":"$B" | wc -l 也可以直接用 grep -c "$A":"$B"
2:重啟zabbix-agent
3:web端添加監(jiān)控項(xiàng)(這個(gè)應(yīng)該不用說了吧)
備注:在設(shè)置的時(shí)候遇到一個(gè)坑嗡载,我用的是HAproxy,但是HAproxy的日志是在rsyslog中配置的仍稀,rsyslog的日志生成的文件權(quán)限是600洼滚,導(dǎo)致zabbix在讀取文件的時(shí)候提示沒有權(quán)限,找了半天解決辦法技潘,最終在rsyslog.conf文件中添加
$FileOwner root
$FileGroup root
$FileCreateMode 0755
$DirCreateMode 0755
$Umask 0022
最終生成的文件是775了遥巴,zabbix就可以讀取文件了