我们使用以下方法获取系统指标。我们还记录用户/机器数据和堆栈。
string _osSql = @"SELECT * FROM Win32_OperatingSystem";
string _metric = string.Format("Metric Data:{0}", Environment.NewLine);
foreach (Screen _screen in Screen.AllScreens)
{
if (_screen.Primary == true)
{
_metric += "Primary";
}
_metric += string.Format("Screen: Width:={0}, Height:={1}{2}", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Environment.NewLine);
}
ManagementObjectSearcher _mgmt = new ManagementObjectSearcher(_osSql);
foreach (ManagementObject _o in _mgmt.Get())
{
_metric += string.Format("OS:={0} - {1}{2}", _o.Properties["Caption"].Value.ToString(), _o.Properties["CSDVersion"].Value.ToString(), Environment.NewLine);
_metric += string.Format("Memory Total:={0}, Available:={1}{2}", _o.Properties["TotalVisibleMemorySize"].Value.ToString(), _o.Properties["FreePhysicalMemory"].Value.ToString(), Environment.NewLine);
_metric += string.Format("Description:={0}{1}", _o.Properties["Description"].Value.ToString(), Environment.NewLine);
_metric += string.Format("TotalVisibleMemorySize:={0}{1}", _o.Properties["TotalVisibleMemorySize"].Value.ToString(), Environment.NewLine);
_metric += string.Format("FreePhysicalMemory:={0}{1}", _o.Properties["FreePhysicalMemory"].Value.ToString(), Environment.NewLine);
}