zoukankan      html  css  js  c++  java
  • 036_监控 HTTP 服务器的状态(测试返回码)

    #!/bin/bash

    #设置变量,url 为你需要检测的目标网站的网址(IP 或域名)
    url=http://192.168.4.5/index.html

    #定义函数 check_http:
    #使用 curl 命令检查 http 服务器的状态
    #-m 设置 curl 不管访问成功或失败,最大消耗的时间为 5 秒,5 秒连接服务为相应则视为无法连接
    #-s 设置静默连接,不显示连接时的连接速度、时间消耗等信息
    #-o 将 curl 下载的页面内容导出到/dev/null(默认会在屏幕显示页面内容)
    #-w 设置 curl 命令需要显示的内容%{http_code},指定 curl 返回服务器的状态码

    check_http(){
    status_code=$(curl -m 5 -s -o /dev/null -w %{http_code} $url)
    }

    while :
    do
          check_http
          if [ $status_code -ne 200 ];then
                 date=$(date +%Y%m%d-%H:%M:%S)
                 #生成报警邮件的内容
                 echo "当前时间为:$date $url 服务器异常,状态码为${status_code}.请尽快排查异常." > /tmp/http$$.pid
                 #指定测试服务器状态的函数,并根据返回码决定是发送邮件报警还是将正常信息写入日志
                 mail -s Warning root < /tmp/http$$.pid
            else
                echo "$url 连接正常" >> /var/log/http.log
             fi
             sleep 5
    done

  • 相关阅读:
    Go jaegerde 应用【logger+gorm+grpc+http】
    Go gRPC 调试工具
    iris和xxl-job整合
    Go Grpc部署到 k8s【端口共享】
    rocketmq事务 go 采用rocketmq-client-go的实现
    Go Grpc部署到 k8s【负载均衡】
    ubuntu18安装Kubernetes 1.20.5
    k8s Python API
    go nacos服务发现
    k8s集群日志收集ELK和graylog
  • 原文地址:https://www.cnblogs.com/luwei0915/p/10516337.html
Copyright © 2011-2022 走看看