예제 #1
0
 public ProbeMonitor(ILogger <ProbeMonitor> logger, IOptions <ProbeMonitorConfig> options, IServiceScopeFactory scopeFactory)
 {
     _logger = logger;
     ProbeMonitorConfig.Validate(options.Value);
     _probeFailureTolerance = options.Value.FailureTolerance;
     _aliveThreshold        = options.Value.AliveThreshold;
     _errorPenaltyPoints    = options.Value.ErrorPenaltyPoints;
     _probe = scopeFactory.CreateScope().ServiceProvider.GetRequiredService <AsterManagerRemote>();
     _probe.ProbeInitiated += ProbeInitiated;
     _probe.ProbeFinished  += ProbeFinished;
     _probe.ProbeErrored   += ProbeErrored;
     _timer          = new Timer(TimeSpan.FromSeconds(options.Value.Interval).TotalMilliseconds);
     _timer.Elapsed += TimerElapsed;
 }
예제 #2
0
 public static void Validate(ProbeMonitorConfig config)
 {
     if (config.FailureTolerance < 0)
     {
         throw new FormatException($"Cannot convert {config.FailureTolerance} to failure tolerance");
     }
     if (config.AliveThreshold < 0)
     {
         throw new FormatException($"Cannot convert {config.AliveThreshold} to alive threshold");
     }
     if (config.ErrorPenaltyPoints < 0)
     {
         throw new FormatException($"Cannot convert {config.ErrorPenaltyPoints} to error penalty points");
     }
     if (config.Interval < 0)
     {
         throw new FormatException($"Cannot convert {config.Interval} to probe interval");
     }
 }