Exemplo n.º 1
0
        private PerfCounterObserver <T> ReadCounterRecords <T>(IObservable <T> source)
        {
            var observer = new PerfCounterObserver <T>();

            source.Subscribe(observer);
            Log.Info($"complete: {observer.Complete}");
            return(observer);
        }
Exemplo n.º 2
0
        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);
        }