protected override void OnTick() { try { PPSIncomingSampler.CumulativeDelta((double)PacketsIncoming); PPSOutgoingSampler.CumulativeDelta((double)PacketsOutgoing); BPSIncomingSampler.CumulativeDelta((double)BytesIncoming); BPSOutgoingSampler.CumulativeDelta((double)BytesOutgoing); AveragePPSIncoming = PPSIncomingSampler.Average(); AveragePPSOutgoing = PPSOutgoingSampler.Average(); AverageBPSIncoming = BPSIncomingSampler.Average(); AverageBPSOutgoing = BPSOutgoingSampler.Average(); // Sample working set (using GC for Mono) WorkingSetSampler.Sample(GC.GetTotalMemory(false)); AverageWorkingSet = WorkingSetSampler.Average(); // Sample CPU long currentLogTime = System.DateTime.Now.Ticks; long currentCpuUsageTime = ProcessInfo.TotalProcessorTime.Ticks; long timeDiff = currentLogTime - LastCpuLogTime.Value; if (timeDiff != 0) { CpuUsageSampler.Sample( ((currentCpuUsageTime - LastCpuUsageTime.Value) * 100 / timeDiff) / Service.ProcessorCount ); AverageCpuUsage = CpuUsageSampler.Average(); } LastCpuLogTime = currentLogTime; LastCpuUsageTime = currentCpuUsageTime; // Collect Compression.Collect(); // Increment the tick NetStat.Tick.Increment(); } catch (Exception ex) { // Log the exception Service.Logger.Log(ex); } }