小洪維尼 发表于 2018-11-13 11:41:57

Nginx负载节点状态监测脚本

  1)脚本需求:开通一个通过web界面展示监控Nginx负载节点的状态。当节点宕机时,以红色展示,当节点正常时以绿色展示。
  
  2)脚本解答:
  # cat monitor.sh
  #!/bin/bash
  #this scripts is created by ywxi at 2018-05-11
  RIPS=(                  #定义监测节点池
  192.168.1.22
  192.168.1.33
  192.168.1.30
  )
  file_location=/usr/share/nginx/html/test.html                  #默认yum安装nginx的站点目录路径
  [ -e "$file_location" ]||mkdir -p `dirname $file_location`    #判断目录是否存在
  function web_result {                                                         #定义curl请求状态值
  rs=`curl -I -s $1|awk 'NR==1{print $2}'`
  return $rs
  }
  function new_row {                                                         #定义web框架
  cat >> $file_location$file_location
页: [1]
查看完整版本: Nginx负载节点状态监测脚本