|
|
@ -1,7 +1,8 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
using System.Net;
|
|
|
|
using System.Runtime.Remoting;
|
|
|
|
using System.Runtime.Remoting;
|
|
|
|
using System.Timers;
|
|
|
|
using System.Threading;
|
|
|
|
using Exceptioneer.WindowsFormsClient;
|
|
|
|
using Exceptioneer.WindowsFormsClient;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using Ninject;
|
|
|
|
using Ninject;
|
|
|
@ -12,7 +13,7 @@ namespace NzbDrone.Providers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class MonitoringProvider
|
|
|
|
public class MonitoringProvider
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private static readonly Logger Logger = LogManager.GetLogger("Host.MonitoringProvider");
|
|
|
|
private static readonly Logger logger = LogManager.GetLogger("Host.MonitoringProvider");
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IISProvider _iisProvider;
|
|
|
|
private readonly IISProvider _iisProvider;
|
|
|
|
private readonly ProcessProvider _processProvider;
|
|
|
|
private readonly ProcessProvider _processProvider;
|
|
|
@ -21,6 +22,7 @@ namespace NzbDrone.Providers
|
|
|
|
|
|
|
|
|
|
|
|
private int _pingFailCounter;
|
|
|
|
private int _pingFailCounter;
|
|
|
|
private Timer _pingTimer;
|
|
|
|
private Timer _pingTimer;
|
|
|
|
|
|
|
|
private Timer _processPriorityCheckTimer;
|
|
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
[Inject]
|
|
|
|
public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider,
|
|
|
|
public MonitoringProvider(ProcessProvider processProvider, IISProvider iisProvider,
|
|
|
@ -43,17 +45,15 @@ namespace NzbDrone.Providers
|
|
|
|
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
|
|
|
|
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
|
|
|
|
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
|
|
|
|
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
|
|
|
|
|
|
|
|
|
|
|
|
var prioCheckTimer = new Timer(5000);
|
|
|
|
_processPriorityCheckTimer = new Timer(EnsurePriority);
|
|
|
|
prioCheckTimer.Elapsed += EnsurePriority;
|
|
|
|
_processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30));
|
|
|
|
prioCheckTimer.Enabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_pingTimer = new Timer(180000) { AutoReset = true };
|
|
|
|
_pingTimer = new Timer(PingServer);
|
|
|
|
_pingTimer.Elapsed += (PingServer);
|
|
|
|
_pingTimer.Change(TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(1));
|
|
|
|
_pingTimer.Start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void EnsurePriority(object sender, ElapsedEventArgs e)
|
|
|
|
public virtual void EnsurePriority(object sender)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var currentProcess = _processProvider.GetCurrentProcess();
|
|
|
|
var currentProcess = _processProvider.GetCurrentProcess();
|
|
|
|
if (currentProcess.Priority != ProcessPriorityClass.Normal)
|
|
|
|
if (currentProcess.Priority != ProcessPriorityClass.Normal)
|
|
|
@ -69,14 +69,21 @@ namespace NzbDrone.Providers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void PingServer(object sender, ElapsedEventArgs e)
|
|
|
|
public virtual void PingServer(object sender)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!_iisProvider.ServerStarted || _configFileProvider.AuthenticationType == AuthenticationType.Windows) return;
|
|
|
|
if (!_iisProvider.ServerStarted) return;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_httpProvider.DownloadString(_iisProvider.AppUrl); //This should preload the home page, making the first load alot faster.
|
|
|
|
ICredentials identity = null;
|
|
|
|
string response = _httpProvider.DownloadString(_iisProvider.AppUrl + "/health");
|
|
|
|
|
|
|
|
|
|
|
|
if (_configFileProvider.AuthenticationType == AuthenticationType.Windows)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
identity = CredentialCache.DefaultCredentials;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_httpProvider.DownloadString(_iisProvider.AppUrl, identity); //This should preload the home page, making the first load faster.
|
|
|
|
|
|
|
|
string response = _httpProvider.DownloadString(_iisProvider.AppUrl + "/health", identity);
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.Contains("OK"))
|
|
|
|
if (!response.Contains("OK"))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -85,7 +92,7 @@ namespace NzbDrone.Providers
|
|
|
|
|
|
|
|
|
|
|
|
if (_pingFailCounter > 0)
|
|
|
|
if (_pingFailCounter > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger.Info("Application pool has been successfully recovered.");
|
|
|
|
logger.Info("Application pool has been successfully recovered.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_pingFailCounter = 0;
|
|
|
|
_pingFailCounter = 0;
|
|
|
@ -93,7 +100,7 @@ namespace NzbDrone.Providers
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_pingFailCounter++;
|
|
|
|
_pingFailCounter++;
|
|
|
|
Logger.ErrorException("Application pool is not responding. Count " + _pingFailCounter, ex);
|
|
|
|
logger.ErrorException("Application pool is not responding. Count " + _pingFailCounter, ex);
|
|
|
|
if (_pingFailCounter > 4)
|
|
|
|
if (_pingFailCounter > 4)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_pingFailCounter = 0;
|
|
|
|
_pingFailCounter = 0;
|
|
|
@ -122,7 +129,7 @@ namespace NzbDrone.Providers
|
|
|
|
}.Submit();
|
|
|
|
}.Submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Logger.FatalException("EPIC FAIL: " + excepion.Message, excepion);
|
|
|
|
logger.FatalException("EPIC FAIL: " + excepion.Message, excepion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|