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); }
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(); }
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(); }
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); } }
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(); } })); }