public async Task <IEnumerable <PerfCounterModel> > GetPerformance(string name, PerformanceCounterType performanceCounterType, TimeframeType timeframeType) { string command = String .Concat(String.Format(this.mainCommandTemplate, name), Environment.NewLine, "Get-SCPerformanceData -VM $VM -PerformanceCounter {0} -Timeframe {1}"); command = String.Format(command, performanceCounterType, timeframeType); var mapper = new ChartMapper(); var objects = await this.psProvider.ExecuteAsync <PSObject>(new PSCommand { ScriptCommand = command }); var listValues = objects.Select(mapper.Map).ToList(); if (listValues.Any()) { var perfCounter = listValues.ToList()[0]; var timestamps = perfCounter.TimeSamples; var values = perfCounter.History; return(values.Select((t, i) => new PerfCounterModel { Value = t, Timestamp = timestamps[i] }).ToList()); } return(Enumerable.Empty <PerfCounterModel>()); }
public async Task <int> GetPerformanceMeanValue(string name, PerformanceCounterType performanceCounterType, TimeframeType timeframeType) { string command = String .Concat(String.Format(this.mainCommandTemplate, name), Environment.NewLine, "Get-SCPerformanceData -VM $VM -PerformanceCounter {0} -Timeframe {1}"); command = String.Format(command, performanceCounterType, timeframeType); var mapper = new ChartMapper(); var objects = await this.psProvider.ExecuteAsync <PSObject>(new PSCommand { ScriptCommand = command }); var listValues = objects.Select(mapper.Map).ToList(); int meanValue = 0; if (listValues.Any()) { var result = listValues.ToList()[0].History; meanValue = result.Sum() / result.Length; } return(meanValue > 0 ? meanValue / 100 : 0); }