Skip to content
Snippets Groups Projects
Commit 16815f4a authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Example for using the new ATxCommon.Monitoring.Cpu class.

parent 4ca08524
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ using System.IO; ...@@ -8,6 +8,7 @@ using System.IO;
using System.Reflection; using System.Reflection;
using System.Timers; using System.Timers;
using ATxCommon; using ATxCommon;
using ATxCommon.Monitoring;
using ATxCommon.NLog; using ATxCommon.NLog;
using ATxCommon.Serializables; using ATxCommon.Serializables;
using NLog; using NLog;
...@@ -46,6 +47,7 @@ namespace ATxService ...@@ -46,6 +47,7 @@ namespace ATxService
public PerformanceCounter CpuCounter; public PerformanceCounter CpuCounter;
private float _cpuLoad; private float _cpuLoad;
private readonly float[] _cpuLoadLastReadings = {0F, 0F, 0F, 0F}; private readonly float[] _cpuLoadLastReadings = {0F, 0F, 0F, 0F};
private Cpu _cpu;
private DateTime _lastUserDirCheck = DateTime.MinValue; private DateTime _lastUserDirCheck = DateTime.MinValue;
...@@ -409,6 +411,8 @@ namespace ATxService ...@@ -409,6 +411,8 @@ namespace ATxService
_loadTimer = new Timer(250); _loadTimer = new Timer(250);
_loadTimer.Elapsed += UpdateCpuLoad; _loadTimer.Elapsed += UpdateCpuLoad;
_loadTimer.Enabled = true; _loadTimer.Enabled = true;
_cpu = new Cpu();
} }
catch (Exception ex) { catch (Exception ex) {
Log.Error("Error in OnStart(): {0}", ex.Message); Log.Error("Error in OnStart(): {0}", ex.Message);
...@@ -499,7 +503,7 @@ namespace ATxService ...@@ -499,7 +503,7 @@ namespace ATxService
// while this method has not finished yet: // while this method has not finished yet:
_mainTimer.Enabled = false; _mainTimer.Enabled = false;
Log.Debug("Current CPU load: {0}", _cpuLoad); Log.Debug("CPU load: {0:#} / {1:#} ({2:#.##})", _cpuLoad, _cpu.Load(), _cpuLoad - _cpu.Load());
try { try {
RunMainTasks(); RunMainTasks();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment