【问题标题】:Any Monit like equivalents for windows OS? [closed]任何类似于 Windows 操作系统的 Monit 等价物? [关闭]
【发布时间】:2009-03-19 19:52:53
【问题描述】:

我看到过“你能在 Windows 上运行 Monit 吗?”这个问题,除非你想使用虚拟机,否则答案似乎是否定的。

那么...实际上是否有任何适用于 Windows 操作系统的小型、类似监视器的应用程序?我正在寻找的不仅仅是监控(其中有数百个应用程序),还有执行脚本或重新启动服务的能力。例如,监控一个网页,如果该页面无响应(不能只看服务,因为服务仍在运行但没有正确响应),则重新启动 Tomcat。

这是针对小型应用程序,而不是大型应用程序,因此不需要重量级/昂贵的解决方案。

【问题讨论】:

  • 哈! - 一个 7 岁的问答被搁置。
  • nssm.cc - 非吸盘服务经理

标签: system-monitoring


【解决方案1】:

我正在使用 RGE Inc (http://www.ipsentry.com/) 的 ipsentry。

已经用了好几年了,救了我很多次。

与他们无关,这不是广告,只是来自满意客户的信息。

【讨论】:

    【解决方案2】:

    我没有找到任何适合我需要的东西,所以我学习了一点 Powershell 脚本并推出了一个对其他人也应该有用的解决方案。假设是 Windows 平台(否则使用 monit!),Powershell 非常强大且简单。

    sample-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
        }
    }
    

    此脚本中唯一的逻辑是它只会在初始失败后尝试重新启动服务一次。这是为了防止出现服务需要一段时间才能重新启动的情况,并且在重新启动时,监视器会不断看到故障并再次重新启动(坏的无限循环)。否则,您几乎可以做任何事情,例如添加电子邮件通知,或者做的不仅仅是重新启动服务。

    此脚本将执行一次,这意味着您需要在外部控制其重复。您可以在脚本中将其置于无限循环中,但这似乎有点不稳定。我使用了windows任务计划程序,像这样执行它: 程序:Powershell.exe 参数:-command "C:\projects\foo\scripts\monitor.ps1" -noprofile 开始于:C:\projects\foo\scripts

    您还可以使用更强大的调度程序,如 VisualCron,将其插入 Windows 服务,或通过 Quart.NET 等应用服务器调度程序。就我而言,任务调度程序工作正常。

    【讨论】:

      【解决方案3】:

      当 Dan Tanner 无法连接、显示错误并且没有重新启动服务时,我稍微调整了他的脚本

      $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
      }
      

      【讨论】:

        【解决方案4】:

        这至少可以部分地使用 Windows 附带的服务控制管理器来完成。它监视服务应用程序并可以在启动时自动启动它们,在崩溃时重新启动它们等。将应用程序编写为服务是一种选择,但如果您不能将应用程序编写为服务,那么您可以尝试包装进程在 Windows 资源工具包中使用 srvany.exe

        关于编写服务的更多信息:https://support.microsoft.com/en-us/kb/137890

        至于实际的监控功能,我不完全确定可用的功能,或者 SCM 功能的扩展。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-11-17
          • 2011-03-01
          • 2010-12-05
          • 2018-10-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多