예제 #1
0
        public static void Test()
        {
            // Poll performance counter 4 times a second
            TimeSpan pollingInterval = TimeSpan.FromSeconds(0.25);

            // Take the total processor utilization performance counter
            string categoryName = "Processor";
            string counterName  = "% Processor Time";
            string instanceName = "_Total";

            // Create an observable that feeds the performance counter periodically
            IObservable <PerformanceCounterSample> source = new PerformanceCounterObservable(categoryName, counterName, instanceName, pollingInterval);

            // Load the observable as a stream in Trill
            var inputStream =
                source.Select(e => StreamEvent.CreateStart(e.StartTime.Ticks, e))                 // Create an IObservable of StreamEvent<>
                .ToStreamable(/*OnCompletedPolicy.Flush(), PeriodicPunctuationPolicy.Count(4)*/); // Create a streamable with a punctuation every 4 events

            // The query
            long windowSize = TimeSpan.FromSeconds(2).Ticks;
            var  query      = inputStream.AlterEventDuration(windowSize).Average(e => e.Value);

            // Egress results and write to console
            query.ToStreamEventObservable().ForEachAsync(e => WriteEvent(e)).Wait();
        }
예제 #2
0
            public Subscription(PerformanceCounterObservable observable, IObserver <PerformanceCounterSample> observer)
            {
                // create a new counter for this subscription
                _counter         = observable._createCounter();
                _pollingInterval = observable._pollingInterval;
                _observer        = observer;

                // seed previous sample to support computation
                _previousSample = _counter.NextSample();

                // create a timer to support polling counter at an interval
                _timer = new Timer(Sample);
                _timer.Change(_pollingInterval.Milliseconds, -1);
            }