private static IEnumerable <GpuConditionPeriod> ToGpuConditionPeriods(this IEnumerable <Snapshot> snapshots, int gpuIndex, Func <GpuStats, Condition> conditionSelector) { var currentPeriod = default(GpuConditionPeriod); foreach (var gpuSnapshot in from snapshot in snapshots where snapshot.MinerStatistics.Gpus.Count > gpuIndex select new { snapshot, gpuStats = snapshot.MinerStatistics.Gpus[gpuIndex] }) { var condition = gpuSnapshot.gpuStats.Mode == GpuMode.Disabled ? Condition.Ok : conditionSelector(gpuSnapshot.gpuStats); if (condition == currentPeriod?.Condition) { currentPeriod.Snapshots.Add(gpuSnapshot.snapshot); } else { if (currentPeriod != null) { currentPeriod.Period = new Period(currentPeriod.Period.Start, gpuSnapshot.snapshot.SnapshotTime); yield return(currentPeriod); } currentPeriod = new GpuConditionPeriod { GpuIndex = gpuIndex, Condition = condition, Period = new Period(gpuSnapshot.snapshot.SnapshotTime, null), Snapshots = new List <Snapshot> { gpuSnapshot.snapshot } }; } } if (currentPeriod != null) { yield return(currentPeriod); } }
private async Task <Alert> CreateAlertAsync(AlertDefinition definition, Miner miner, GpuThresholdAlertParameters parameters, GpuConditionPeriod conditionPeriod, CancellationToken token) { var metadata = CreateMetadata(null, parameters, conditionPeriod); var detailMessages = CreateDetailMessages(metadata, parameters); return(await _alertFactory.CreateAlertAsync(definition, miner, metadata, DefaultAlertMessage, detailMessages, token)); }
protected override AlertMetadata CreateMetadata(AlertMetadata existingMetadata, GpuThresholdAlertParameters parameters, GpuConditionPeriod conditionPeriod) { var fanSpeeds = conditionPeriod.GpuStats .Select(s => (int?)s.FanSpeed) .Concat(new[] { existingMetadata?.Value?.Min, existingMetadata?.Value?.Max }) .ToList(); return(new AlertMetadata { GpuIndex = conditionPeriod.GpuIndex, Threshold = new AlertThresholdMetadata { Min = parameters.MaxValue, Max = parameters.MaxValue, GpuMetric = Metric.FanSpeed }, Value = new AlertValueMetadata { Condition = conditionPeriod.Condition, Min = fanSpeeds.Min(), Max = fanSpeeds.Max() } }); }
protected abstract AlertMetadata CreateMetadata(AlertMetadata existingMetadata, GpuThresholdAlertParameters parameters, GpuConditionPeriod conditionPeriod);
protected override AlertMetadata CreateMetadata(AlertMetadata metadata, GpuThresholdAlertParameters parameters, GpuConditionPeriod conditionPeriod) { var hashrates = conditionPeriod.GpuStats .Select(s => (int?)s.EthereumHashrate) .Concat(new[] { metadata?.Value?.Min, metadata?.Value?.Max }) .ToList(); return(new AlertMetadata { GpuIndex = conditionPeriod.GpuIndex, Threshold = new AlertThresholdMetadata { Min = parameters.MaxValue, Max = parameters.MaxValue, GpuMetric = Metric.Hashrate }, Value = new AlertValueMetadata { Condition = conditionPeriod.Condition, Min = hashrates.Min(), Max = hashrates.Max() } }); }