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

Use a public field to represent the load state

Refers to #36
parent bd9275b7
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,11 @@ namespace ATxCommon.Monitoring ...@@ -55,6 +55,11 @@ namespace ATxCommon.Monitoring
/// <returns>The average CPU load from the last four readings.</returns> /// <returns>The average CPU load from the last four readings.</returns>
public float Load { get; private set; } public float Load { get; private set; }
/// <summary>
/// Flag representing whether the load is considered to be high or low.
/// </summary>
public bool HighLoad { get; private set; }
/// <summary> /// <summary>
/// How often (in ms) to check the CPU load. /// How often (in ms) to check the CPU load.
/// </summary> /// </summary>
...@@ -116,8 +121,10 @@ namespace ATxCommon.Monitoring ...@@ -116,8 +121,10 @@ namespace ATxCommon.Monitoring
Log.Debug("CPU monitoring initializing PerformanceCounter (takes one second)..."); Log.Debug("CPU monitoring initializing PerformanceCounter (takes one second)...");
_cpuCounter.NextValue(); _cpuCounter.NextValue();
Thread.Sleep(1000); Thread.Sleep(1000);
Log.Debug("CPU monitoring current load: {0:0.0}", _cpuCounter.NextValue()); var curLoad = _cpuCounter.NextValue();
// _monitoringTimer = new Timer(_interval); Log.Debug("CPU monitoring current load: {0:0.0}", curLoad);
// now initialize the load state:
HighLoad = curLoad > _limit;
_monitoringTimer = new Timer(_interval); _monitoringTimer = new Timer(_interval);
_monitoringTimer.Elapsed += UpdateCpuLoad; _monitoringTimer.Elapsed += UpdateCpuLoad;
} }
...@@ -177,6 +184,7 @@ namespace ATxCommon.Monitoring ...@@ -177,6 +184,7 @@ namespace ATxCommon.Monitoring
/// Raise the "LoadAboveLimit" event. /// Raise the "LoadAboveLimit" event.
/// </summary> /// </summary>
protected virtual void OnLoadAboveLimit() { protected virtual void OnLoadAboveLimit() {
HighLoad = true;
LoadAboveLimit?.Invoke(this, EventArgs.Empty); LoadAboveLimit?.Invoke(this, EventArgs.Empty);
} }
...@@ -184,6 +192,7 @@ namespace ATxCommon.Monitoring ...@@ -184,6 +192,7 @@ namespace ATxCommon.Monitoring
/// Raise the "LoadBelowLimit" event. /// Raise the "LoadBelowLimit" event.
/// </summary> /// </summary>
protected virtual void OnLoadBelowLimit() { protected virtual void OnLoadBelowLimit() {
HighLoad = false;
LoadBelowLimit?.Invoke(this, EventArgs.Empty); LoadBelowLimit?.Invoke(this, EventArgs.Empty);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment