public Task StartAsync(CancellationToken cancellationToken)
        {
            _scheduler = new Timer(Callback, null,
                                   TimeSpan.FromSeconds(1), _captureInterval);
            return(Task.CompletedTask);

            #region old
            //不用下面create这种方式来调用信息
            //static void Callback(object state)
            //{
            //    Console.WriteLine($"[{DateTimeOffset.Now}]{PerformanceMetrics.Create()}");
            //}
            #endregion

            async void Callback(object state)
            {
                var counter = new PerformanceMetrics
                {
                    Processor = _processorMetricsCollector.GetUsage(),
                    Memory    = _memoryMetricsCollector.GetUsage(),
                    Network   = _networkMetricsCollector.GetThroughput()
                };
                await _metricsDeliver.DeliverAsync(counter);
            }
        }
예제 #2
0
        //通过options来传递配置
        public Task DeliverAsync(PerformanceMetrics counter)
        {
            //Console.WriteLine($"[{DateTimeOffset.UtcNow}]{counter}");

            _logForDelivery(_logger, DateTimeOffset.Now, counter, _deliverTo, _transport, null);

            Console.WriteLine($"[{DateTimeOffset.Now}]Deliver performance counmter {counter}" +
                              $"to {_deliverTo} via {_transport}");

            return(Task.CompletedTask);
        }
예제 #3
0
 public long GetThroughput()
 {
     return(PerformanceMetrics.Create().Network);
 }
예제 #4
0
 long IMemoryMetricsCollector.GetUsage()
 {
     return(PerformanceMetrics.Create().Memory);
 }
예제 #5
0
 public int GetUsage()
 {
     return(PerformanceMetrics.Create().Processor);
 }