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); } }
//通过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); }
public long GetThroughput() { return(PerformanceMetrics.Create().Network); }
long IMemoryMetricsCollector.GetUsage() { return(PerformanceMetrics.Create().Memory); }
public int GetUsage() { return(PerformanceMetrics.Create().Processor); }