public void SetUp() { var scheduler = Mock.Create <IScheduler>(); Mock.Arrange(() => scheduler.ExecuteEvery(Arg.IsAny <Action>(), Arg.IsAny <TimeSpan>(), Arg.IsAny <TimeSpan?>())) .DoInstead <Action, TimeSpan, TimeSpan?>((action, _, __) => _sampleAction = action); _cpuSampleTransformer = Mock.Create <ICpuSampleTransformer>(); _cpuSampler = new CpuSampler(scheduler, _cpuSampleTransformer, new ProcessStatic()); _cpuSampler.Start(); }
public CpuSampler(IScheduler scheduler, ICpuSampleTransformer cpuSampleTransformer, IProcessStatic processStatic) : base(scheduler, TimeSpan.FromSeconds(CpuSampleIntervalSeconds)) { _cpuSampleTransformer = cpuSampleTransformer; _processStatic = processStatic; try { _processorCount = System.Environment.ProcessorCount; _lastSampleTime = DateTime.UtcNow; _lastProcessorTime = GetCurrentUserProcessorTime(); } catch (Exception ex) { Log.Error($"Unable to get CPU sample. No CPU metrics will be reported. Error : {ex}"); Stop(); } }