1

我已在 Windows Azure 环境中成功配置 ARR,将 Web 服务器实例添加到服务器场。

使用服务器场中的健康检查选项,超时或无响应的实例会变得不健康。

我的问题是

  1. 而不是 ARR 网络农场(每 10 秒进行一次健康检查)ping 网站,是否有可能或网络角色本身 ping 回 ARR 服务器并说我要关闭?

  2. 是否可以从 Web 角色 ping ARR 服务器并说我要关闭?或者这是有任何可用的最佳方法。

    请建议。

4

1 回答 1

2

我希望我们的 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)
    }

}

于 2014-12-16T23:30:37.843 回答