2009-03-19 11 views
11

「WindowsでMonitを実行できますか?」という質問がありました.VMを使用しない限り、答えは「いいえ」と表示されます。Windows OSのMonitのようなものはありますか?

だから、実際にはWindows OSのための小さなフットプリントのmonitのようなアプリケーションはありますか?私が探しているのは、何百ものアプリケーションがある監視だけでなく、スクリプトを実行したり、サービスを再起動したりする機能です。たとえば、Webページを監視し、そのページが応答しなくなった場合(サービスがまだ実行されているが適切に応答していないためにサービスを見るだけでは)、Tomcatを再起動します。

これは小さなアプリケーション用であり、大きなアプリケーションではないため、重量があり高価なソリューションは望ましくありません。

+0

ほらを再起動しませんでした! - 7歳の質問と回答が保留になりました。 –

答えて

6

私は自分のニーズに合ったものは見つけられませんでしたので、Powershellの小さなスクリプトを学び、他の人にも役立つはずのソリューションを紹介しました。 Windowsプラットフォーム(それ以外の場合はmonit!を使用します)を仮定すると、Powershellは本当に強力で簡単です。

サンプルmonitor.ps1スクリプト:

$webClient = new-object System.Net.WebClient 

################################################### 
# BEGIN USER-EDITABLE VARIABLES 

# the URL to ping 
$HeartbeatUrl = "http://someplace.com/somepage/" 

# the response string to look for that indicates things are working ok 
$SuccessResponseString = "Some Text" 

# the name of the windows service to restart (the service name, not the display name) 
$ServiceName = "Tomcat6" 

# the log file used for monitoring output 
$LogFile = "c:\temp\heartbeat.log" 

# used to indicate that the service has failed since the last time we checked. 
$FailureLogFile = "c:\temp\failure.log" 

# END USER-EDITABLE VARIABLES 
################################################### 

# create the log file if it doesn't already exist. 
if (!(Test-Path $LogFile)) { 
    New-Item $LogFile -type file 
} 

$startTime = get-date 
$output = $webClient.DownloadString($HeartbeatUrl) 
$endTime = get-date 

if ($output -like "*" + $SuccessResponseString + "*") { 
    # uncomment the below line if you want positive confirmation 
    #"Success`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds" >> $LogFile 

    # remove the FailureLog if it exists to indicate we're in good shape. 
    if (Test-Path $FailureLogFile) { 
     Remove-Item $FailureLogFile 
    } 

} 
else { 
    "Fail`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds" >> $LogFile 

    # restart the service if this is the first time it's failed since the last successful check. 
    if (!(Test-Path $FailureLogFile)) { 
     New-Item $FailureLogFile -type file 
     "Initial failure:" + $startTime.DateTime >> $FailureLogFile 
     Restart-Service $ServiceName 
    } 
} 

このスクリプトでは唯一のロジックは、それが初期不良のみの後に一度サービスを再起動しようとするということです。これは、サービスの再起動に時間がかかり、再起動している間、モニターは失敗を見続けてから再開します(悪い無限ループ)。それ以外の場合は、電子メール通知の追加やサービスの再起動だけでは何もできません。

このスクリプトは一度実行されます。つまり、外部で繰り返しを制御する必要があります。あなたはスクリプトの中で無限ループに入れることができますが、それはちょっと薄れているようです。 プログラム:Powershell.exe 引数:-command "C:¥projects¥foo¥scripts¥monitor.pop1" -noprofile 開始場所:C:\ projects \ foo \ scripts以下のようにしてWindowsタスクスケジューラを使用します。

VisualCronのようなより堅牢なスケジューラを使用して、Windowsサービスにプラグインするか、Quart.NETのようなアプリケーションサーバースケジューラを使用することもできます。私の場合、タスクスケジューラは正常に動作します。

0

私はRGE Inc(http://www.ipsentry.com/)のipsentryを使用しています。

これを数年間使用してきたので、何度も何度も救ってくれました。

これは広告ではなく、満足している顧客からの情報です。

0

これは、Windowsに付属のService Control Managerを使用して、少なくとも部分的に達成できます。それはサービスアプリケーションを監視し、起動時に自動的に起動し、クラッシュ時に自動的に起動します。アプリケーションとしてサービスを書くこともオプションですが、アプリケーションをサービスとして書くことができない場合は、プロセスをラップすることができますWindowsリソースキットでsrvany.exeを使用してください。サービスを書くことについて

詳細情報:実際の監視機能についてはhttps://support.microsoft.com/en-us/kb/137890

、私が利用可能何全くわからない、またはSCMの機能を拡張します。

1

私は彼が接続できなかったとき、ダン・タナースクリプトを少し調整し、エラーを示し、サービス

$webClient = new-object System.Net.WebClient 

################################################### 
# BEGIN USER-EDITABLE VARIABLES 

# the URL to ping 
$HeartbeatUrl = "http://localhost:8080/" 

# the response string to look for that indicates things are working ok 
$SuccessResponseString = "Apache" 

# the name of the windows service to restart (the service name, not the display name) 
$ServiceName = "Tomcat6" 

# the log file used for monitoring output 
$LogFile = "c:\temp\log.log" 

# used to indicate that the service has failed since the last time we checked. 
$FailureLogFile = "c:\temp\log2.log" 

# END USER-EDITABLE VARIABLES 
################################################### 

# create the log file if it doesn't already exist. 
if (!(Test-Path $LogFile)) { 
    New-Item $LogFile -type file 
} 

$startTime = get-date 
try { 
    $output = $webClient.DownloadString($HeartbeatUrl) 
    $endTime = get-date 

    if ($output -like "*" + $SuccessResponseString + "*") { 
     # uncomment the below line if you want positive confirmation 
     #"Success`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds" >> $LogFile 

     # remove the FailureLog if it exists to indicate we're in good shape. 
     if (Test-Path $FailureLogFile) { 
      Remove-Item $FailureLogFile 
     } 

    } 
    else { 
     "Fail`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds" >> $LogFile 

     # restart the service if this is the first time it's failed since the last successful check. 
     if (!(Test-Path $FailureLogFile)) { 
      New-Item $FailureLogFile -type file 
      "Initial failure:" + $startTime.DateTime >> $FailureLogFile 
      Restart-Service $ServiceName 
     } 
    } 
    }catch [Net.WebException] { 
     New-Item $FailureLogFile -type file 
     "Initial failure:" + $startTime.DateTime + $_.Exception.ToString() >> $FailureLogFile 
     Restart-Service $ServiceName 
} 
関連する問題