Zabbix Key Monitoring-mysql-nginx-php

Source: Internet
Author: User
Tags curl fpm mysql query mysql version

Key monitoring-mysql-nginx-php One, Zabbix monitoring MySQL is configured on the client: [[email protected] ~]# vim /usr/local/zabbix/ etc/chk_mysql.sh#!/bin/bash# ---------------------------------------------------------------------------- ---# filename:    check_mysql.sh# revision:    1.0#  date:        2015/06/09# author:       dengyun# email:       [email protected]# website:      www.ttlsa.com# Description: # Notes:        ~# -------------------------------------------------------------------------------#  Copyright:   2015  (c)  dengyun# license:     #   User name mysql_user= ' root ' #  password mysql_pwd= ' YYIRPFNHIOFSD ' #  host address/ipmysql_host= ' 127.0.0.1 ' #  port MySQL _port= ' 3306 ' #  data connection mysql_conn= "/Usr/local/bin/mysqladmin -u${mysql_user} -p${mysql_pwd} -h${mysql_host} -p${mysql_port} "#   Correct parameters if [ $# -ne  "1"  ];then    echo  "arg error!"  fi#  get data Case $1 in    uptime)          result= ' ${mysql_conn} status|cut -f2 -d ': "|cut -f1 -d" T "         echo  $result          ;;     com_update)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "Com_update" |cut -d "|"  -f3 '         echo  $result           ;;     slow_queries)         result= ' ${MYSQL_CONN}  status |cut -f5 -d ":" |cut -f1 -d "O"         echo  $result           ;;     com_select)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "Com_select" |cut -d "|"  -f3 '         echo  $result                 ;;     com_rollback)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "Com_rollback" |cut -d "|"  -f3 '                 echo   $result                   ;;     questions)         result= ' ${MYSQL_CONN}&NBSp;status|cut -f4 -d ":" |cut -f1 -d "S" '                  echo  $result                   ;;     com_insert)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "Com_insert" |cut -d "|"  -f3 '                 echo   $result                   ;;     com_delete)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "Com_delete" |cut -d "|"  -f3 '                 echo   $result    &NBsp;             ;;     com_commit)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "Com_commit" |cut -d "|"  -f3 '                 echo   $result                   ;;     bytes_sent)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "bytes_sent"  |cut -d "|"  -f3 '                 echo   $result                   ;; bytes_received)         result= ' ${mysql_conn} extended-status |grep -w  "bytes_received"  |cut -d "|"  -f3 '                 echo   $result                   ;;     com_begin)         result= ' ${MYSQL_CONN}  extended-status |grep -w  "Com_begin" |cut -d "|"  -f3 '                 echo   $result                   ;;         *)         echo  " Usage:$0 (uptime| com_update| slow_queries| Com_select| com_rollback| questions| Com_insert| com_delete| Com_commit| Bytes_sent| bytes_received| Com_begin) "         ;; esac[[email protected] ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf add:#  at the back Get MySQL version userparameter=mysql.version,mysql -v #   get MySQL performance metrics, this is the script defined above userparameter= mysql.status[*],/usr/local/zabbix/etc/chk_mysql.sh $1 #   get MySQL Run status userparameter= mysql.ping,mysqladmin -uroot -pyyirpfnhiofsd -p3306 -h127.0.0.1  ping |  grep -c alive Service End value: [[email protected] ~]# zabbix_get -s 10.44.37.221  -p10050 -k mysql.status[com_update]297 second, monitoring Php-fpm[[email protected] ~]# vim  /usr/local/php/etc/php-fpm.confpm.status_path = /status    //to get rid of; Enable monitoring of FPM status [[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf location ~  ^/(status|ping) $         {         fastcgi_pass   127.0.0.1:9000;        include fastcgi_params;         fastcgi_index index.php;         fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;         allow 127.0.0.1;        allow  10.170.236.125;        deny all;         }[[email protected] ~]# service nginx restart[[email protected ] etc]# curl -s http://localhost/status  //tests if you can see the status of PHP-FPM, there is information to create a monitoring script: [[ email protected] ~]# vim /usr/local/zabbix/etc/chk_php-fpm.sh#!/bin/bash#monitor  Php-fpm status from zabbix#lincense:gpl#mail:[email protected] #date:2015.04.15source  /etc/bashrc >/dev/null 2>&1source /etc/profile >/dev/null 2>&1log=/usr/local/zabbix/etc/phpfpm_status.logcurl  -s http://localhost/status > $LOGpool () { awk  '/pool/ {print  $NF} '  $ Log}process_manager () { awk  '/process manager/ {print  $NF} '   $LOG}start_since () {  awk  '/start since:/ {print  $NF} '   $LOG}accepted_conn () {         awk  '/accepted conn:/ {print  $NF} '   $LOG}listen_queue () {         awk  '/^ (listen queue:)/ {print  $NF} '   $LOG} Max_listen_queue () {        awk  '/max listen queue:/  {print  $NF} '   $LOG}listen_queue_len () {        awk  '/listen queue len:/ {print  $NF} '   $LOG}idle_processes () {         awk  '/idle processes:/ {print  $NF} '   $LOG}active_processes () {         awk  '/^ (active processes:)/ {print  $NF} '   $LOG}total_processes () {        awk  '/total processes:/ {print  $NF} '   $LOG}max_active_processes () {        awk  '/max active  processes:/ {print  $NF} '   $LOG}max_children_reached () {         awk  '/max children reached:/ {print  $NF} '   $LOG}slow_requests () {         awk  '/slow requests:/ {print  $NF} '  $ log}case  "$"  inpool)  pool ;; Process_manager)  process_manager ;; Start_since)  start_since ;; Accepted_conn)  accepted_conn ;; Listen_queue)  listen_queue ;; Max_listen_queue)  max_listen_queue ;; Listen_queue_len)  listen_queue_len ;; idle_processes)  idle_processes ;; active_processes)  active_processes ;; total_processes)  total_processes ;; max_active_processes)  max_active_processes ;; max_children_reached)  max_children_reached ;; slow_requests)  slow_requests ;; *) echo  "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue |listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached| slow_requests} "ESAC reference script file [[email protected] ~]# vim /usr/local/zabbix/etc/zabbix_ agentd.conf#userparameter=php-fpm[*],/usr/local/zabbix/etc/chk_php-fpm.sh  "$" UserParameter= phpfpm.status.pool,/usr/local/zabbix/etc/chk_php-fpm.sh pooluserparameter=phpfpm.status.process.manager,/ usr/local/zabbix/etc/chk_php-fpm.sh process_manageruserparameter=phpfpm.status.start.since,/usr/local/ zabbix/etc/chk_php-fpm.sh start_sinceuserparameter=phpfpm.status.accepted.conn,/usr/local/zabbix/etc/chk_php-fpm.sh  Accepted_connuserparameter=phpfpm.status.listen.queue,/usr/local/zabbix/etc/chk_php-fpm.sh listen_ Queueuserparameter=phpfpm.status.max.listen.queue,/usr/local/zabbix/etc/chk_php-fpm.sh max_listen_ Queueuserparameter=phpfpm.status.listen.queue.len,/usr/local/zabbix/etc/chk_php-fpm.sh listen_queue_ Lenuserparameter=phpfpm.status.idle.processes,/usr/local/zabbix/etc/chk_php-fpm.sh idle_ Processesuserparameter=phpfpm.status.active.processes,/usr/local/zabbix/etc/chk_php-fpm.sh active_ Processesuserparameter=phpfpm.status.total.processes,/usr/local/zabbix/etc/chk_php-fpm.sh total_ Processesuserparameter=phpfpm.status.max.active.processes,/usr/local/zabbix/etc/chk_php-fpm.sh max_active _processesuserparameter=phpfpm.status.max.children.reached,/usr/local/zabbix/etc/chk_php-fpm.sh max_ Children_reacheduserparameter=phpfpm.status.slow.requests,/usr/local/zAbbix/etc/chk_php-fpm.sh slow_requests[[email protected] ~]# /etc/init.d/zabbix_agentd  restart[[email protected] etc]# curl http://127.0.0.1/statuspool:                  wwwprocess manager:       dynamicstart time:            27/Apr/2016:14:21:33 +0800start since:           85601accepted conn:        37078listen  queue:         0max listen queue:      13listen queue len:     128idle processes:        2active processes:     1total processes:       3max active processes: 5max children reached: 4slow requests:         0 the role of each parameter is described below: the name of the POOL:PHP-FPM pool, which is generally supposed to be wwwprocess manage: The management method of the process, PHP-FPM supports three kinds of management methods, namely Static,dynamic and OnDemand, which are generally the time of dynamicstart time:php-fpm startup, Either restart or reload will update the time here START SINCE:PHP-FPM the time elapsed since startup, default is seconds Accepted conn: Number of connections currently received listen  Queue: The number of requests waiting for a connection in the queue, if this number is not 0, it is best to increase the number of FPM in the process max listen queue: The maximum value of the connection request is waiting in the queue since FPM started listen  Queue len: Socket queue Size to wait for connection idle processes: Number of idle processes active processes: Number of active processes total  Processes: Total number of processes max active processes: The maximum number of active processes since FPM started, and if this value is less than the current Max_children, this value can be smaller max  Children reached: When PM tries to start more processes, but because of the max_children limit, no more processes are started. If this value is not 0, then you can appropriately increase the number of FPM processes slow requests: The number of slow requests, generally if this value is not 0, then there may be slow PHP process, generally a bad MySQL query is the biggest culprit. Server Authentication: [[Email protected] ~]# zabbix_get -s 10.44.37.221 -p 10050 -k  phpfpm.status.idle. processes127        //get to Data description configuration No problem, next Add template on Web page iii. monitoring Nginx[[email  protected] ~]# vim /usr/local/nginx/conf/nginx.conf added under PHP-PFM:    location  /nginx-status {        stub_status on;         access_log on;        allow  127.0.0.1;        allow 10.170.236.125;         deny all;        }[[email  protected] ~]# vim /usr/local/zabbix/etc/chk_nginx.sh#!/bin/bash# script to  Fetch nginx statuses for tribily monitoring systems# author: [email  protected]# license: gplv2# set variablesbkup_date= '/bin/date +%Y%m%d ' LOG= "/ Data/log/zabbix/webstatus.log "host=127.0.0.1port= "# functions to return nginx statsfunction active {/usr/" bin/curl  "/http $HOST: $PORT/nginx-status"  2>/dev/null| grep  ' Active '  | awk   ' {print  $NF} '}function reading {/usr/bin/curl  "/http $HOST: $PORT/nginx-status"  2>/dev/null| grep  ' Reading '  | awk  ' {print $2} '}function writing  {/usr/bin/curl  "/http $HOST: $PORT/nginx-status"  2>/dev/null| grep  ' Writing '  | awk  ' {print $4} '}function waiting {/usr/bin/curl  '//$HOST: $PORT/ Nginx-status " 2>/dev/null| grep  ' waiting '  | awk  ' {print $6} '}function  accepts {/usr/bin/curl  "http:/$HOST $PORT/nginx-status"  2>/dev/null| awk nr ==3 | awk  ' {print $1} '}function handled {/usr/bin/curl  '//$HOST: $PORT/ Nginx-status " 2>/dev/null| awk nr==3 | awk  ' {print $2} '}function requests {/usr/bin/curl  ' http:/$HOST $PORT/nginx-status " 2>/dev/null| awk NR==3 | awk " {print $3 } '}# run the requested function$1 is configured on the monitored side: [[email protected] ~]$ vim / Usr/local/zabbix/etc/zabbix_agentd.conf added at the end: userparameter=nginx.accepts,/usr/local/zabbix/etc/chk_nginx.sh  acceptsuserparameter=nginx.handled,/usr/local/zabbix/etc/chk_nginx.sh handleduserparameter= nginx.requests,/usr/local/zabbix/etc/chk_nginx.sh requestsuserparameter=nginx.connections.active,/usr/ Local/zabbix/etc/chk_nginx.sh activeuserparameter=nginx.connections.reading,/usr/local/zabbix/etc/chk_ nginx.sh readinguserparameter=nginx.connections.writing,/usr/local/zabbix/etc/chk_nginx.sh  Writinguserparameter=nginx.connections.waiting,/usr/local/zabbix/etc/chk_nginx.sh waiting is monitored to view nginx status: [[ email protected] etc]#  curl http://127.0.0.1/nginx-statusactive connections: 1 server accepts handled  requests 67561 67561 159860 Reading: 0 Writing: 1 Waiting:  0Activeconnections: Number of active connections to backend;server accepts 67561:nginx  67,561 connections were processed; handled: Successfully created 67,561 handshake ; requests: 159860 requests were processed in total. Reading:nginx read the number of headers of the client;writing: nginx  the number of headers returned to the client;waiting: nginx  request processing is complete, The connection that is waiting for the next request instruction. Test on the server [[Email protected] ~]# zabbix_get -s 10.44.37.221 -p 10050 -k   "nginx.accepts" 3151 Note: When you add a template to the Web, the key value (the key, the Web is linked by a key value to the monitoring server) is the same as the value after the monitor end Userparameter, for example nginx.accepts


This article from the "Personal blog" blog, reproduced please contact the author!

Zabbix Key Monitoring-mysql-nginx-php

Related Article

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.