public Worker( ILogger <Worker> logger, IOptions <Settings> settings, IHostEnvironment environment) { _logger = logger; _environment = environment; _settings = settings.Value; this.ipmiFanControlClients = new Dictionary <string, IPMIFanControlClient>(); this.tempClients = new Dictionary <string, TemperatureClient>(); this._lastTenTempsCache = new Dictionary <string, List <int> >(); if (_settings.HostSettings == null) { throw new Exception("no config found!"); } foreach (var hostSetting in _settings.HostSettings) { if (this._lastTenTempsCache.ContainsKey(hostSetting.Name)) { throw new Exception("Duplicate client name detected."); } this._lastTenTempsCache.Add(hostSetting.Name, new List <int>(_settings.RollingAverageNumberOfTemps)); var fanControlClient = new IPMIFanControlClient() { _logger = logger, PathToIpmiToolIfNotDefault = hostSetting.PathToIpmiToolIfNotDefault, Platform = this._settings.Platform, IpmiHost = hostSetting.Host, IpmiUser = hostSetting.User, IpmiPassword = hostSetting.Password, }; this.ipmiFanControlClients.Add(hostSetting.Name, fanControlClient); TemperatureClient client = null; if (string.Compare(hostSetting.Type, "ipmi", true) == 0) { client = new TemperatureIpmiClient(fanControlClient, hostSetting.RegexToRetrieveTemp, CheckTemperatureControlCommand); } else if (string.Compare(hostSetting.Type, "ssh_lm_sensors", true) == 0) { client = new TemperatureLMSensorsClient(hostSetting.LMHost, hostSetting.LMUser, hostSetting.LMPassword, hostSetting.RegexToRetrieveTemp, this._logger); } else { throw new Exception("no match host type"); } this.tempClients.Add(hostSetting.Name, client); } }
private async Task SwitchToAutomaticTempControl(IPMIFanControlClient fanControlClient, CancellationToken cancellationToken) { _logger.LogInformation("Attempting switch to automatic mode."); await fanControlClient.ExecuteIpmiToolCommand( EnableAutomaticTempControlCommand, cancellationToken); fanControlClient.OperatingMode = OperatingMode.Automatic; }
private async Task SwitchToManualTempControl(IPMIFanControlClient fanControlClient, CancellationToken cancellationToken) { try { var timeSinceLastActivation = DateTime.UtcNow - _timeFellBelowTemp; var threshold = TimeSpan.FromSeconds(_settings.BackToManualThresholdInSeconds); if (timeSinceLastActivation < threshold) { _logger.LogWarning( "Manual threshold not crossed yet. Staying in Automatic mode for at least another " + $"{(int)(threshold - timeSinceLastActivation).TotalSeconds} seconds."); return; } _logger.LogInformation("Attempting switch to manual mode."); await fanControlClient.ExecuteIpmiToolCommand( DisableAutomaticTempControlCommand, cancellationToken); var fanSpeedCommand = string.Format( StaticFanSpeedFormatString, _settings.ManualModeFanPercentage.ToString("X")); await fanControlClient.ExecuteIpmiToolCommand(fanSpeedCommand, cancellationToken); fanControlClient.OperatingMode = OperatingMode.Manual; } catch (Exception ex) { this._logger.LogError(ex + ""); await StopAsync(cancellationToken); } }