Exemple #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Start");

            IObservable <PerformanceSample> performanceCounterObservable =
                PerfCounterObservable.FromRealTime(
                    TimeSpan.FromSeconds(1),
                    new[]
            {
                @"\Processor(_Total)\% Processor Time",
                @"\Memory(_Total)\% Committed Bytes In Use",
                @"\Memory(_Total)\Available MBytes"
            });

            VisualRxInitResult info = await VisualRxSettings.Initialize(
                VisualRxWcfDiscoveryProxy.Create());

            Console.WriteLine(info);

            performanceCounterObservable
            .Monitor("Step 1", 1)
            .Where(v => v.CounterName == "% Processor Time")
            .Monitor("Step 2", 1)
            .Select(m => (int)(m.Value / 10))
            .Select(m => new string('-', m))
            .Subscribe(
                v => Console.WriteLine(v));

            Console.ReadKey();
        }
Exemple #2
0
        public void PerformanceCounterProbeFirst()
        {
            PerformanceSample[] result;
            var startTime = DateTimeOffset.UtcNow;

            using (var playback = new Playback())
            {
                ((IPlaybackConfiguration)playback).AddInput(
                    () => PerfCounterObservable.FromRealTime(TimeSpan.FromSeconds(1), @"\Processor(_Total)\% User Time").Take(1),
                    typeof(PerfCounterPartitionTypeMap),
                    typeof(PerfCounterTypeMap));

                var query = playback.GetObservable <PerformanceSample>();

                var enumerable = playback.BufferOutput(query);

                playback.Run();

                result = enumerable.ToArray();
            }
            var endTime = DateTimeOffset.UtcNow;

            Assert.AreEqual(1, result.Length);

            Assert.AreEqual("% User Time", result[0].CounterName, false, CultureInfo.InvariantCulture);
            Assert.AreEqual("Processor", result[0].CounterSet, false, CultureInfo.InvariantCulture);
            Assert.AreEqual("_Total", result[0].Instance, false, CultureInfo.InvariantCulture);
            Assert.AreEqual(DateTimeKind.Local, result[0].Timestamp.Kind);
            var dto = new DateTimeOffset(result[0].Timestamp);

            Assert.IsTrue(dto >= startTime);
            Assert.IsTrue(dto <= endTime);
        }
Exemple #3
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);
        }
Exemple #4
0
        public void BlgCount()
        {
            var observable = PerfCounterObservable.FromFile(BlgFileName);

            int count = observable.Count()
                        .Wait();

            Assert.AreEqual(6000, count);
        }
Exemple #5
0
        private void TcpSyntheticCounters_Load(object sender, EventArgs e)
        {
            _playback = new Playback();
            _playback.AddRealTimeSession(PerfCounterSessionName);

            IObservable <PerformanceSample> perfCounters = PerfCounterObservable.FromRealTime(TimeSpan.FromSeconds(1), CounterPaths);

            _subscription = perfCounters.ObserveOn(_chart).Subscribe(CounterAdded);

            _playback.Start();
        }
Exemple #6
0
        public void BlgStatistics()
        {
            var observable = PerfCounterObservable.FromFile(BlgFileName);

            int count = observable
                        .Where(p => p.CounterSet == "PhysicalDisk")
                        .Count()
                        .Wait();

            Assert.AreEqual(3000, count);
        }
Exemple #7
0
        public void PerformanceCounterProbeBadCounterName()
        {
            Exception error = null;

            using (PerfCounterObservable.FromRealTime(TimeSpan.FromHours(1), "blah")
                   .Subscribe(Observer.Create <PerformanceSample>(_ => { }, e => error = e)))
            {
                Assert.IsNotNull(error);
                Assert.IsInstanceOfType(error, typeof(Exception));
                Assert.AreEqual("PDH_CSTATUS_BAD_COUNTERNAME", error.Message);
            }
        }
Exemple #8
0
        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());
        }
Exemple #9
0
        public void BlgStatistics()
        {
            var observable = PerfCounterObservable.FromFile(BlgFileName);

            int count = 0;

            observable.Where(p => p.CounterSet == "PhysicalDisk").ForEach(
                x =>
            {
                count++;
            });

            Assert.AreEqual(3000, count);
        }
Exemple #10
0
        public void BlgCount()
        {
            var observable = PerfCounterObservable.FromFile(BlgFileName);

            int count = 0;

            observable.ForEach(
                x =>
            {
                count++;
            });

            Assert.AreEqual(6000, count);
        }
Exemple #11
0
        public static string EventLogWithTx()
        {
            //http://blogs.endjin.com/2014/05/event-stream-manipulation-using-rx-part-2/

            return(ExecuteVoidCommand(() =>
            {
                //NuGet package Tx to read from Windows Performance counters
                var perfCounterStream = PerfCounterObservable.FromRealTime(TimeSpan.FromSeconds(1),
                                                                           new[]
                {
                    @"\Processor(_Total)\% Processor Time",
                    @"\Memory(_Total)\% Committed Bytes In Use",
                    @"\Memory(_Total)\Available MBytes"
                })
                                        .Buffer(TimeSpan.FromSeconds(1));

                perfCounterStream.Subscribe();

                //NuGet package Tx to read from Windows Event Log
                var eventStream = EvtxObservable.FromLog("TestLog")
                                  .Merge(EvtxObservable.FromLog("TestLog2"))
                                  .Select(eventRecord => new Event()
                {
                    Record = eventRecord
                })
                                  .ComposeLatest(perfCounterStream,
                                                 (evt, perfSamples) =>
                {
                    evt.PerformanceSamples.AddRange(perfSamples);
                    return evt;
                })
                                  .Buffer(TimeSpan.FromSeconds(2));

                using (eventStream.Subscribe(new EventObserver()))
                {
                    Console.WriteLine("Press any key to unsubscribe");
                    Console.ReadKey();
                }
            }));
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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());
        }