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

Logging changes only.

Refers to #36
parent b0d538de
Branches
No related tags found
No related merge requests found
...@@ -83,13 +83,12 @@ namespace ATxCommon.Monitoring ...@@ -83,13 +83,12 @@ namespace ATxCommon.Monitoring
_limit = 25; _limit = 25;
_probation = 40; _probation = 40;
Log.Debug("Initializing CPU monitoring..."); Log.Debug("Initializing CPU monitoring...");
try { try {
_cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); _cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
Log.Debug("CPU monitoring initializing PerformanceCounter (takes 1s)..."); Log.Debug("CPU monitoring initializing PerformanceCounter (takes 1s)...");
_cpuCounter.NextValue(); _cpuCounter.NextValue();
Thread.Sleep(1000); Thread.Sleep(1000);
Log.Debug("CPU monitoring current load: {0}", _cpuCounter.NextValue()); Log.Debug("CPU monitoring current load: {0:0.0}", _cpuCounter.NextValue());
// _monitoringTimer = new Timer(_interval); // _monitoringTimer = new Timer(_interval);
_monitoringTimer = new Timer(_interval); _monitoringTimer = new Timer(_interval);
_monitoringTimer.Elapsed += UpdateCpuLoad; _monitoringTimer.Elapsed += UpdateCpuLoad;
...@@ -106,12 +105,10 @@ namespace ATxCommon.Monitoring ...@@ -106,12 +105,10 @@ namespace ATxCommon.Monitoring
private void UpdateCpuLoad(object sender, ElapsedEventArgs e) { private void UpdateCpuLoad(object sender, ElapsedEventArgs e) {
_monitoringTimer.Enabled = false; _monitoringTimer.Enabled = false;
try { try {
Log.Trace("load values: {0}, average: {1}", string.Join(", ", _loadReadings), _load);
// ConstrainedCopy seems to be the most efficient approach to shift the array: // ConstrainedCopy seems to be the most efficient approach to shift the array:
Array.ConstrainedCopy(_loadReadings, 1, _loadReadings, 0, 3); Array.ConstrainedCopy(_loadReadings, 1, _loadReadings, 0, 3);
_loadReadings[3] = _cpuCounter.NextValue(); _loadReadings[3] = _cpuCounter.NextValue();
_load = _loadReadings.Average(); _load = _loadReadings.Average();
Log.Trace("load values: {0}, average: {1}", string.Join(", ", _loadReadings), _load);
if (_loadReadings[3] > _limit) { if (_loadReadings[3] > _limit) {
Log.Debug("CPU load ({0}) violating limit ({1})!", _loadReadings[3], _limit); Log.Debug("CPU load ({0}) violating limit ({1})!", _loadReadings[3], _limit);
_behaving = 0; _behaving = 0;
...@@ -119,10 +116,10 @@ namespace ATxCommon.Monitoring ...@@ -119,10 +116,10 @@ namespace ATxCommon.Monitoring
} else { } else {
_behaving++; _behaving++;
if (_behaving == _probation) { if (_behaving == _probation) {
Log.Debug("CPU load below limit for {0} cycles, yay!", _probation); Log.Debug("CPU load below limit for {0} cycles, passing probation!", _probation);
// TODO: fire callback for load behaving well // TODO: fire callback for load behaving well
} else if (_behaving > _probation) { } else if (_behaving > _probation) {
Log.Debug("CPU load behaving well since {0} cycles.", _behaving); Log.Trace("CPU load behaving well since {0} cycles.", _behaving);
} else if (_behaving < 0) { } else if (_behaving < 0) {
Log.Warn("Integer wrap around happened, resetting probation counter!"); Log.Warn("Integer wrap around happened, resetting probation counter!");
_behaving = 0; _behaving = 0;
...@@ -135,6 +132,8 @@ namespace ATxCommon.Monitoring ...@@ -135,6 +132,8 @@ namespace ATxCommon.Monitoring
finally { finally {
_monitoringTimer.Enabled = true; _monitoringTimer.Enabled = true;
} }
Log.Info("CPU load: {0:0.0} {1}", _loadReadings[3], _loadReadings[3] < Limit ? " [" + _behaving + "]" : "");
Log.Trace("load values: {0}, average: {1}", string.Join(", ", _loadReadings), _load);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment