Development program implementation of NGINX agent node status check and Web interface display

Source: Internet
Author: User

Introduction to Implementing Features:

Using shell programs and HTTP services to implement a smart monitoring Nginx agent node status check, and then through the Web interface real-time refresh display results, is not a little surprised by such a tall program? Then take a look at it!
To the employer: this course can reflect the students shell programming skills, as well as the Nginx Proxy Enterprise actual combat and the ability to harness.

Different students of the three ways to share the implementation, you crossing, you see which classmate better, please comment.


The first implementation of the script: Youjinyi video download See address : http://down.51cto.com/data/1914201

#!/bin/shport=80conf_path= "/application/nginx/conf" conf_file= "nginx.conf" html_path= "/application/nginx/html" Html_file= "Monitor.html" rs= ($ (grep web-a  "$conf _path/$conf _file" |grep -v  ' # ' |awk -F "[  :]+ "  ' {print $2} ')) Function proxy_delrs () {   local ip=$1 sed  -i  '/' $ip '/s/\ (. *\),/\1 down;/g '   $conf _path/$conf _file " &> /dev/null  [ $? -eq 0 ] && return 0 | |  return 1}function proxy_addrs () { local ip=$1 sed -i  '/' $ip '/s/\ (. *\) Down;/\1;/g '   "$conf _path/$conf _file" &NBSP;&AMP;&GT;&NBSP;/DEV/NULL&NBSP;[&NBSP;$?&NBSP;-EQ&NBSP;0&NBSP;]  && return 0 | |  return 1}function proxy_getwebservertype () { local ip=$1 local srvtype=$ ( curl -i -s  $ip |awk  '/^server/{print $2} ' |cut -b1-5)  if [  "$ Srvtype " ==  "Apach"  ];then  return 1 elif [  "$srvType"  ==  "Nginx"  ];then  return 0 else  return 2 fi}function proxy_ Getrsstatus () { local ip=$1 if cat  $conf _path/$conf _file|grep  "$ip: $port \ (. *\) Down; "  &>/dev/null;then  return 0 else  return 1 fi}function  proxy_checkrshealth () { local ip=$1 if [  "$ (nmap  $ip  -p  $port |awk   '/80/{print $2} ') '  ==  ' open '  ];then  return 0 else    return 1 fi}function proxy_checkhtml () {  if [ ! -f  "$html _ path/$html _file " ];then  proxy_htmlinit fi}function proxy_sendstattohtml () {  local rs=$1 local string=$2 if [  $string  ==  "Good"  ];then   sed -i /' &LT;TD&NBSp;id= ' ${rs} ' _stat '/s#.*# '     <td id= ' $rs ' _stat align= ' center '  bgcolor= ' Green ' > Good </td> ' #g   $html _path/$html _file  &>/dev/null else   sed -i /' <td id= ' ${rs} ' _stat '/s#.*# '     <td id= ' $rs ' _stat align= "center"  bgcolor= "Red" > Bad </td> ' #g   $html _path/$html _file  &>/dev/null fi  proxy_getWebServerType  $rs  case $? in 0)    sed -i /' <td id= ' ${rs} ' _type '/s#.*# '     <td id= ' ${rs} ' _ type align= "center" > Nginx </td> ' #g   $html _path/$html _file  &>/ dev/null ;;  1)   sed -i /' <td id= ' ${rs} ' _type '/s#.*# '     <td  Id= ' ${rs} ' _type align= "center" > Apache </td> ' #g   $html _path/$html _file   &>/dev/null ;;  2)   sed -i /' <td id= ' ${rs} ' _type '/s#.*# '     <td  Id= ' ${rs} ' _type align= "center" > Unknow </td> ' #g   $html _path/$html _file   &>/dev/null ;;  *)  ;;  esac}function proxy_htmlinit () { echo   ' 

Second classmate Implementation script: Wang Shuo download to see the video address : http://down.51cto.com/data/1914011

#!/bin/bash#author: stanley wang#mail:  #Version:  1.0#description: this is a  script for nginx proxy health check.### #def  vars######### #RS = (   172.16.1.191  172.16.1.192) port=80html_file= "/var/html/www/index.html" declare -a RSTATUS## #main ############# #function  checkrs () {  local i=0  for  (i=0;i<${#RS [*] };i++))   do    rstatus[$I]= ' nmap ${rs[$I]} -p  $PORT |grep  " Open "|wc -l '   done}function output () {    if [ ${rstatus[0]}  -eq 0 ];then       #echo   "${rs[$i]} is down!"       sed -i  ' 22 s/.*/<td align= ' Center " bgcolor=" Red "><font size=" >down!<\/font><\/td>/g   $html _file     Elif [ ${rstatus[0]} -eq 1 ];then       #echo   "${rs[$i]} is ok!"       sed -i  ' 22 s/.*/<td align= ' Center " bgcolor=" Green "><font size=" >ok!<\/font><\/td>/g   $html _file     fi    if [ ${rstatus[1]} -eq 0 ];then        #echo   "${rs[$i]} is down!"       sed -i  ' 28 s/.*/<td align= ' Center " bgcolor=" Red "><font size=" >down!<\/font><\/td>/g   $html _file     elif [ ${rstatus[1]} -eq 1 ];then       #echo   "${RS [$i]}  is ok! "       sed -i  ' 28 s/.*/<td align= ' Center " bgcolor=" Green "><font size=" >ok!<\/font>&Lt;\/td>/g '   $html _file    fi}while truedo  checkrs   Outputsleep 2done

Third Implementation script: Liu Lei download watch video tutorial : http://down.51cto.com/data/1914011

#!/bin/bashrs_arr= (     10.0.0.11    10.0.0.22     10.0.0.33    ) file_location=/var/html/test.htmlfunction web_result {     rs= ' curl -i -s $1|awk  ' nr==1{print $2} '      return  $rs}function new_row {cat >>  $file _location <<eof<tr> <td bgcolor= "$4" >$1</td><td bgcolor= "$4" >$2</td><td bgcolor= "$4" > $3</td></tr>eof}function auto_html {    web_result $2     rs=$?    if [  $rs  -eq 200 ]     then new_row $1 $2 up green    else new_row $1  $2 down red    fi}main () {while truedocat >>  $file _ Location <<eof< h4>he status of rs :

This article is from the old boy education 19 students after class work sharing.

This article is from the "Old boy Linux ops" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/1589685

Development program implementation of NGINX agent node status check and Web interface display

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.