private bool TxBlg(FileObject fileObject, string outputFile) { DateTime startTime = DateTime.Now; IObservable <PerformanceSample> observable = default(IObservable <PerformanceSample>); PerfCounterObserver <PerformanceSample> counterSession = default(PerfCounterObserver <PerformanceSample>); List <PerformanceSample> records = new List <PerformanceSample>(); List <CsvCounterRecord> csvRecords = new List <CsvCounterRecord>(); // testing pdh found invalid data when using concurrently lock (_lockObj) { Log.Debug($"observable creating: {fileObject.FileUri}"); observable = PerfCounterObservable.FromFile(fileObject.FileUri); Log.Debug($"observable created: {fileObject.FileUri}"); counterSession = ReadCounterRecords(observable); Log.Debug($"finished total ms: {DateTime.Now.Subtract(startTime).TotalMilliseconds} reading: {fileObject.FileUri}"); records = counterSession.Records; } foreach (var record in records) { if (!string.IsNullOrEmpty(record.Value.ToString())) { string counterValue = record.Value.ToString() == "NaN" ? "0" : record.Value.ToString(); try { csvRecords.Add(new CsvCounterRecord() { Timestamp = record.Timestamp, CounterName = record.CounterPath.Replace("\"", "").Trim(), CounterValue = Decimal.Parse(counterValue, NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint), Object = record.CounterSet?.Replace("\"", "").Trim(), Counter = record.CounterName.Replace("\"", "").Trim(), Instance = record.Instance?.Replace("\"", "").Trim(), NodeName = fileObject.NodeName, FileType = fileObject.FileDataType.ToString(), RelativeUri = fileObject.RelativeUri }); } catch (Exception ex) { Log.Exception($"stringValue:{counterValue} exception:{ex}", record); } } else { Log.Warning($"empty counter value:", record); } } fileObject.Stream.Write(csvRecords); Log.Info($"records: {records.Count()} {csvRecords.Count}"); return(true); }
public void BlgCount() { var observable = PerfCounterObservable.FromFile(BlgFileName); int count = observable.Count() .Wait(); Assert.AreEqual(6000, count); }
public void BlgStatistics() { var observable = PerfCounterObservable.FromFile(BlgFileName); int count = observable .Where(p => p.CounterSet == "PhysicalDisk") .Count() .Wait(); Assert.AreEqual(3000, count); }
public void BlgFirst() { var observable = PerfCounterObservable.FromFile(BlgFileName); var result = observable.FirstAsync().Wait(); Assert.IsNotNull(result); Assert.AreEqual(@"Avg. Disk Bytes/Read", result.CounterName, false, CultureInfo.InvariantCulture); Assert.AreEqual("PhysicalDisk", result.CounterSet, false, CultureInfo.InvariantCulture); Assert.AreEqual("0 C:", result.Instance, false, CultureInfo.InvariantCulture); Assert.AreEqual(DateTimeKind.Local, result.Timestamp.Kind); Assert.AreEqual(new DateTimeOffset(634969254188440000, TimeSpan.Zero), result.Timestamp.ToUniversalTime()); }
public void BlgStatistics() { var observable = PerfCounterObservable.FromFile(BlgFileName); int count = 0; observable.Where(p => p.CounterSet == "PhysicalDisk").ForEach( x => { count++; }); Assert.AreEqual(3000, count); }
public void BlgCount() { var observable = PerfCounterObservable.FromFile(BlgFileName); int count = 0; observable.ForEach( x => { count++; }); Assert.AreEqual(6000, count); }
public void BlgPivot() { // this query pivots the counters as one row per instance, containing all the counters // so we get 3000/5 = 600 rows, each with 5 counters var observable = PerfCounterObservable.FromFile(BlgFileName); var grouped = from a in observable where a.CounterSet == "PhysicalDisk" group a by new { a.Machine, a.Instance, a.Timestamp } into groups from g in groups.ToArray() select new { groups.Key.Machine, groups.Key.Instance, groups.Key.Timestamp, Counters = g }; var all = grouped.ToEnumerable().ToArray(); Assert.AreEqual(600, all.Length); }
public void BlgFirst() { PerformanceSample result = null; var observable = PerfCounterObservable.FromFile(BlgFileName); observable .Take(1) .ForEach( x => { result = x; }); Assert.IsNotNull(result); Assert.AreEqual(@"Avg. Disk Bytes/Read", result.CounterName, false, CultureInfo.InvariantCulture); Assert.AreEqual("PhysicalDisk", result.CounterSet, false, CultureInfo.InvariantCulture); Assert.AreEqual("0 C:", result.Instance, false, CultureInfo.InvariantCulture); Assert.AreEqual(DateTimeKind.Local, result.Timestamp.Kind); Assert.AreEqual(new DateTimeOffset(634969254188440000, TimeSpan.Zero), result.Timestamp.ToUniversalTime()); }