Zabbix monitoring Nginx Log configuration detailed

Source: Internet
Author: User

Be able to monitor the client link response time and response return code in the log, monitor the number of 50.100.1000 over 10 seconds, monitor the average response time, and monitor the number of response return codes, respectively, 302.404.502
Nginx Log Format:

| Log_format upstream2 ' $remote _addr $remote _user [$time _local] "$request" $http _host '
' $body _bytes_sent ' $http _referer ' "$http _user_agent" $ssl _protocol $ssl _cipher '
' $request _time [$status] [$upstream _status] [$upstream _response_time] "$upstream _addr";

Is the time to establish a connection from the Nginx back end (php-cgi) until the data is accepted and the connection is closed.

Discovery Script:

[root@rack_proxy_black_list/etc/zabbix/scripts]# Cat nginx-log_analysis.py
#!/usr/bin/env python
# -------------------------------------------------------------------------------

# -------------------------------------------------------------------------------
# Notice
# Nginx Auto Discovery access.log
# log Auto Discovery
###############################################################################
Import OS
Import JSON
T=os.popen ("" "Ls/data/wwwlogs |grep ' log$ '" ")
logs = []
For log in T.readlines ():
R = Os.path.basename (Log.strip ())
Logs + = [{' {#LOGNAME} ': R}]
Print json.dumps ({' Data ': logs},sort_keys=true,indent=4,separators= (', ', ': '))
Userparameter:

#nginx Log
userparameter=nginx_log,/etc/zabbix/scripts/nginx-log_analysis.py
Userparameter=nginxdy10.1000[*],/usr/bin/tail-1000/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' |awk-f '] ' {print $$1} ' | awk ' {if ($$0 >) total+=1}end{print total} '
Userparameter=nginxdy10.100[*],/usr/bin/tail-100/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' | Awk-f '] ' {print $$1} ' | awk ' {if ($$0 >) total+=1}end{print total} '
Userparameter=nginxdy10.50[*],/usr/bin/tail-50/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' |awk -F '] ' {print $$1} ' | awk ' {if ($$0 >) total+=1}end{print total} '
Userparameter=nginxpj.1000[*],/usr/bin/tail-1000/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' | Awk-f '] ' {print $$1} ' | awk ' {Sum+=$$0}end{b=sum/1000;print B} '
Userparameter=nginxpj.100[*],/usr/bin/tail-100/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' |awk -F '] ' {print $$1} ' | awk ' {Sum+=$$0}end{b=sum/1000;print B} '
Userparameter=nginxpj.50[*],/usr/bin/tail-50/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' |awk- F '] ' {print $$1} ' | awk ' {Sum+=$$0}end{b=sum/1000;print B} '
Userparameter=nginx100.404[*],/usr/bin/tail-100/data/wwwlogs/$1 |awk ' {a=nf-2}{print $a} ' |grep 404|wc-l
Userparameter=nginx50.404[*],/usr/bin/tail-50/data/wwwlogs/$1 |awk ' {a=nf-2}{print $a} ' |grep 404|wc-l
Userparameter=nginx100.502[*],/usr/bin/tail-100/data/wwwlogs/$1 |awk ' {a=nf-2}{print $a} ' |grep 502|wc-l
Userparameter=nginx100.301[*],/usr/bin/tail-100/data/wwwlogs/$1 |awk ' {a=nf-2}{print $a} ' |grep 301|wc-l
Userparameter=nginx50.502[*],/usr/bin/tail-50/data/wwwlogs/$1 |awk ' {a=nf-2}{print $a} ' |grep 502|wc-l
Userparameter=nginx50.301[*],/usr/bin/tail-50/data/wwwlogs/$1 |awk ' {a=nf-2}{print $a} ' |grep 301|wc-l
Userparameter=nginxmax[*],/usr/bin/tail-50/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' |awk-f '] ' {print $$1} ' |awk ' BEGIN {max = 0} {if ($$1>max) max=$$1 fi} end {print ' max= ', max} ' |awk ' {print $$2} '
Userparameter=nginxmin[*],/usr/bin/tail-50/data/wwwlogs/$1 |awk ' {a=nf-1}{print $a} ' |awk-f ' [' {print $$2} ' |awk-f '] ' {print $$1} ' |awk ' BEGIN {min = 1999999} {if ($$1<min) min=$$1 fi} end {print min} '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.