nginx 로그 방 문 량 통계

1. 방문 IP 에 따 른 UV 통계
awk '{print $1}' access.log|sort | uniq -c |wc -l
2. 방문 URL 통계 PV
awk '{print $7}' access.log|wc -l
3. 가장 자주 방문 하 는 URL 조회
awk '{print $7}' access.log|sort | uniq -c |sort -n -k 1 -r|more
4. 가장 자주 방문 하 는 IP 조회
awk '{print $1}' access.log|sort | uniq -c |sort -n -k 1 -r|more
5. 시간 대별 로 그 를 보기
cat access.log| sed -n '/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p'|more
zabbix 프로필 추가
vim /etc/zabbix/zabbix_server.conf
[html] view plain copy### Option: AlertScriptsPath
Full path to location of custom alert scripts.
Default depends on compilation options.
Mandatory: no
Default:
AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/local/zabbix/sbin
vim /usr/local/zabbix/sbin/nginx-status.py [python] view plain copyimport urllib2,base64,sys,getopt,re
def Usage(): print "Usage: Nginx-Status.py -h 127.0.0.1 -p 80 -a [active|accepted|handled|requests|reading|writting|waiting]" sys.exit(2)
def main(): if len(sys.argv) < 6: Usage()
try:  
    opts,args = getopt.getopt(sys.argv[1:], "h:p:a:")  
    Dict = dict(opts)  
except getopt.GetoptError:  
    Usage()  

Nginx_url = "http://" + Dict['-h'] + ":" + Dict['-p'] + "/nginx_status"  
Nginx_req = urllib2.Request(Nginx_url)  
Nginx_res = urllib2.urlopen(Nginx_req)  
Output_key = re.findall(r'\d{1,8}', Nginx_res.read())  

if ( Dict['-a'] == "active"):  
        print Output_key[0]  
elif ( Dict['-a'] == "accepted"):  
        print Output_key[1]  
elif ( Dict['-a'] == "handled"):  
        print Output_key[2]  
elif ( Dict['-a'] == "requests"):  
        print Output_key[3]  
elif ( Dict['-a'] == "reading"):  
        print Output_key[4]  
elif ( Dict['-a'] == "writting"):  
        print Output_key[5]  
elif ( Dict['-a'] == "waiting"):  
        print Output_key[6]  
else:  
        print "unknown!!"  
        sys.exit(1)  

if name == 'main': main()
nginx_status_templates.xml[html] view plain copy 2.0 2015-11-03T01:37:04Z nginx-status nginx-status nginx-status nginx-status nginx-accepted 10 0 nginx-status.py["-h","{HOST.IP}","-p","80","-a","accepted"] 30 90 365 0 3 0 0 0 0 1 0 0 0 nginx-active 10 0 nginx-status.py["-h","{HOST.IP}","-p","80","-a","active"] 30 90 365 0 3 0 0 0 0 1 0 0 0 nginx-handled 10 0 nginx-status.py["-h","{HOST.IP}","-p","80","-a","handled"] 30 90 365 0 3 0 0 0 0 1 0 0 0 nginx-reading 10 0 nginx-status.py["-h","{HOST.IP}","-p","80","-a","reading"] 30 90 365 0 3 0 0 0 0 1 0 0 0 nginx-requests 10 0 nginx-status.py["-h","{HOST.IP}","-p","80","-a","requests"] 30 90 365 0 3 0 0 0 0 1 0 0 0 nginx-waiting 10 0 nginx-status.py["-h","{HOST.IP}","-p","80","-a","waiting"] 30 90 365 0 3 0 0 0 0 1 0 0 0 nginx-writting 10 0 nginx-status.py["-h","{HOST.IP}","-p","80","-a","writting"] 30 90 365 0 3 0 0 0 0 1 0 0 0 nginx-clients-status 900 200 0.0000 100.0000 1 1 0 1 0 0.0000 0.0000 0 0 0 0 0 0 00C800 0 2 0 nginx-status nginx-status.py["-h","{HOST.IP}","-p","80","-a","active"] 1 0 C80000 0 2 0 nginx-status nginx-status.py["-h","{HOST.IP}","-p","80","-a","reading"] 2 0 0000C8 0 2 0 nginx-status nginx-status.py["-h","{HOST.IP}","-p","80","-a","waiting"] 3 0 C800C8 0 2 0 nginx-status nginx-status.py["-h","{HOST.IP}","-p","80","-a","writting"] nginx-socket-status 900 200 0.0000 100.0000 1 1 0 1 0 0.0000 0.0000 0 0 0 0 0 0 00C800 0 2 0 nginx-status nginx-status.py["-h","{HOST.IP}","-p","80","-a","handled"] 1 0 0000C8 0 2 0 nginx-status nginx-status.py["-h","{HOST.IP}","-p","80","-a","requests"] 2 0 C800C8 0 2 0 nginx-status nginx-status.py["-h","{HOST.IP}","-p","80","-a","accepted"]

좋은 웹페이지 즐겨찾기