如何使网站Ping ARR服务器并说我要下线



我已经成功配置了Windows Azure环境中的ARR, web服务器实例被添加到服务器场。

在服务器场中使用运行状况检查选项,超时或不响应的实例被设置为不健康。

My Question is

  1. 而不是ARR web farm(每10秒做一次健康检查)ping网站,是否有可能或者web角色本身ping回ARR服务器并说我down了?

  2. 是否有可能从web角色ping ARR服务器并说我正在走下坡路?或者这是最好的方法。

    请建议。

我希望我们的ARR设置有一些额外的通知,我把这个PowerShell脚本放在一起,每小时运行一次,检查健康状态,并在任何主机服务器被视为不健康时通过电子邮件通知我。我们也使用其他外部资源,每分钟ping一次网络农场,当它不能被看到时提醒我们(Pingdom)。我有一种感觉,你在寻找比这更多的东西,但我希望它能有所帮助。

#----- First add a reference to the MWA dll ----#
$dll=[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
 
#----- Get the manager and config object ----#
$mgr = new-object Microsoft.Web.Administration.ServerManager
$conf = $mgr.GetApplicationHostConfiguration()
 
#----- Get the webFarms section ----#
$section = $conf.GetSection("webFarms")
$webFarms = $section.GetCollection()
#----- Define an array for html fragments ----#
$fragments=@()
#----- Check each webfarm ----#
foreach ($webFarm in $webFarms)
{
    $Name= $webFarm.GetAttributeValue("name");
    #Get the servers in the farm
    $servers = $webFarm.GetCollection()
    #Write-Host  "Farm Name: " $Name
    $fragments+= "<b>Farm Name: $Name</b>"
    $fragments+="<br>"
    foreach($server in $servers)
    {
         $ip= $server.GetAttributeValue("address")
         $hostname= ([system.net.dns]::GetHostByAddress($ip)).hostname
         #Get the ARR section
         $arr = $server.GetChildElement("applicationRequestRouting")
         $counters = $arr.GetChildElement("counters")
         $isHealthy=$counters.GetAttributeValue("isHealthy")
         $state= $counters.GetAttributeValue("state")
         switch ($state) 
         { 
                0 {$state= "Available"} 
                1 {$state= "Drain"} 
                2 {$state= "Unavailable"} 
                default {$state= "Non determinato"}
         }
 
        if( $isHealthy)
        {
            $isHealthy="Healthy"
            $fragments+="$hostname -- $ip -- $state -- $isHealthy"
            $fragments+="<br>"
        }
        else
        {
            $isHealthy="Not Healthy"
            $notHealthy="RED ALERT!! This is what we trained for!"
            $fragments+="$hostname -- $ip -- $state -- $isHealthy"
            $fragments+="<br>"
        }        
         #Write-Host -NoNewLine $hostname " " $ip " " $state " " $isHealthy
         #NEW LINE
         #Write-Host
    }
    #NEW LINE
    #Write-Host
    if($notHealthy){
    #write the results to HTML formated email
        
        $smtpServer = "SMTP server"
        $smtpFrom = "email address"
        $smtpTo = "email address"
        $messageSubject = "Unhealthy Web Server"
        $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
        $message.Subject = $messageSubject
        $message.IsBodyHTML = $true
        $message.Body = $fragments
        $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($message)
    }
}

相关内容

  • 没有找到相关文章

最新更新