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

Adapt ATxDiagnostics to show multiple performance monitors

Fixes #53
parent cf07428f
No related branches found
No related tags found
No related merge requests found
using System; using System.Diagnostics;
using System.Diagnostics; using System.Linq;
using System.Management;
using System.Reflection; using System.Reflection;
using ATxCommon; using ATxCommon;
using ATxCommon.Monitoring; using ATxCommon.Monitoring;
...@@ -30,67 +29,43 @@ namespace ATxDiagnostics ...@@ -30,67 +29,43 @@ namespace ATxDiagnostics
logConfig.LoggingRules.Add(logRuleConsole); logConfig.LoggingRules.Add(logRuleConsole);
LogManager.Configuration = logConfig; LogManager.Configuration = logConfig;
var commonAssembly = Assembly.GetAssembly(typeof(ATxCommon.Monitoring.Cpu)); // set the default performance monitors:
var perfMonitors = new[] {"CPU", "PhysicalDisk"};
// if requested explicitly as a command line parameter, override them:
if (args.Length > 1)
perfMonitors = args[1].Split(',');
var commonAssembly = Assembly.GetAssembly(typeof(Cpu));
var commonVersionInfo = FileVersionInfo.GetVersionInfo(commonAssembly.Location); var commonVersionInfo = FileVersionInfo.GetVersionInfo(commonAssembly.Location);
Log.Info("ATxCommon library version: {0}", commonVersionInfo.ProductVersion); Log.Info("ATxCommon library version: {0}", commonVersionInfo.ProductVersion);
Log.Debug("Free space on drive [C:]: " + Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:"))); Log.Debug("Free space on drive [C:]: " + Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:")));
Log.Info("Checking CPU load using ATxCommon.Monitoring...");
var cpu = new Cpu {
Interval = 250,
Limit = 25,
Probation = 4, // 4 * 250 ms = 1 second
Enabled = true
};
System.Threading.Thread.Sleep(10000);
cpu.Enabled = false;
Log.Info("Finished checking CPU load using ATxCommon.Monitoring.\n");
Log.Info("Checking CPU load using WMI..."); if (perfMonitors.Contains("CPU")) {
for (int i = 0; i < 10; i++) { Log.Info("Watching CPU load using ATxCommon.Monitoring...");
WmiQueryCpuLoad(); var cpu = new Cpu {
System.Threading.Thread.Sleep(1000); Interval = 250,
Limit = 50,
Probation = 4, // 4 * 250 ms = 1 second
LogPerformanceReadings = LogLevel.Info,
Enabled = true
};
} }
Log.Info("Finished checking CPU load using WMI.\n");
}
private static int WmiQueryCpuLoad() {
Log.Trace("Querying WMI for CPU load...");
var watch = Stopwatch.StartNew();
var queryString = "SELECT Name, PercentProcessorTime " +
"FROM Win32_PerfFormattedData_PerfOS_Processor";
var opts = new EnumerationOptions {
Timeout = new TimeSpan(0, 0, 10),
ReturnImmediately = false,
};
var searcher = new ManagementObjectSearcher("", queryString, opts);
Int32 usageInt32 = -1;
var managementObjects = searcher.Get();
if (managementObjects.Count > 0) {
Log.Trace("WMI query returned {0} objects.", managementObjects.Count);
foreach (var mo in managementObjects) {
var obj = (ManagementObject)mo;
var usage = obj["PercentProcessorTime"];
var name = obj["Name"];
usageInt32 = Convert.ToInt32(usage); if (perfMonitors.Contains("PhysicalDisk")) {
Log.Debug("CPU usage {1}: {0}", usageInt32, name); Log.Info("Watching I/O load using ATxCommon.Monitoring...");
var disk = new PhysicalDisk {
} Interval = 250,
} else { Limit = 0.25F,
Log.Error("No objects returned from WMI!"); Probation = 4, // 4 * 250 ms = 1 second
LogPerformanceReadings = LogLevel.Info,
Enabled = true
};
} }
managementObjects.Dispose(); while (true) {
searcher.Dispose(); System.Threading.Thread.Sleep(10000);
}
watch.Stop();
Log.Trace("WMI query took {0} ms.", watch.ElapsedMilliseconds);
return usageInt32;
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment