Linux Service Monitoring scripts

Source: Internet
Author: User
Tags array definition

  • Configure the servers to be monitored
      • Array definition: host_ports= (Host_name=host_port=uri_path)
        Host_name for easy-to-identify server names
        Host_port for server IP and service port
        Uri_path the request path for the economy
      • Open firewall port for script running server, intranet IP and extranet IP, but be consistent with Host_port
        -A rh-firewall-1-input-m state--state new-m tcp-p tcp-s 121.45.111.17--dport 8090-j ACCEPT
  • Monitoring results logging
      • First record the date
        echo  ' date + '%y-%m-%d %h:%m:%s '  >  $log
      • Select Notify_host, Need to provide the interface to send mail, so the previous definition of the array will have the mail interface host in front, find the first healthy host can be notify_host
            if [ -z  $notify _host ]; then         notify_host= $host _port     fi
      • Check the log file after checking, more than 1 lines to send an email notification
        curl http://$notify _host/admin/monitor.html?log= $log  > /dev/null 2>&1
  • Crontab timed Run monitoring scripts
      • Crontab configuration, check every 20 minutes
        */20 * * * */soft/monitor.sh >>/soft/logs/monitor-cron.log
      • Run effect, check every two minutes when testing

      • Email notification



Script Content Log=/soft/logs/monitor.logecho ' date + '%y-%m-%d%h:%m:%s 'echo ' date + '%y-%m-%d%h:%m:%s ' > $loghost_ports= (caifuxiang-slave-test=121.45.111.17: 8080=/activate.htmlghcaiyuan-slave-test=121.45.111.17: 8080=/activate.htmlcaifuxiang-app=121.45.111.17: 8080=/activate.htmlcaifuxiang-app2=121.45.111.17: 8080=/activate.htmlghcaiyuan-app=121.45.111.17: 8080=/activate.htmlgucaiyuan-app2=121.45.111.17: 8080=/activate.htmlcaifuxiang-master-upload=121.45.111.17: 8090=/upload/crossdomain.xmlghcaiyuan-master-upload=121.45.111.17: 8090=/upload/crossdomain.xml)#echo ${host_ports[*]}For ((i=0;i<${#host_ports [@]};++i)) Dohost_name= ' echo ${host_ports[i]}|cut-d ' = '-F 1 'host_port= ' echo ${host_ports[i]}|cut-d ' = '-F 2 'uri_path= ' echo ${host_ports[i]}|cut-d ' = '-f 3 '#echo $host _portif curl/http/$host _port$uri_path >/dev/null 2>&1 Then#echo "$host _name is OK"if [-Z $notify _host]; Thennotify_host= $host _portfiElseecho "$host _name is not OK"echo "$host _name is not OK" >> $logfi Donelog_lines= ' cat $log |wc-l '#echo "$log lines: $log _lines"if [$log _lines-gt 1]; Thenecho "Send notify email using: $notify _host, log: $log"Curl/http/$notify _host/admin/monitor.html?log= $log >/dev/null 2>&1Elseecho "Everything is OK"fi


From for notes (Wiz)

List of attachments

    Linux Service Monitoring scripts

    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.