Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
2eef7120
Commit
2eef7120
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Add a local WMI query method to ATxDiagnostics.
parent
e3912d8d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ATxDiagnostics/ATxDiagnostics.cs
+48
-1
48 additions, 1 deletion
ATxDiagnostics/ATxDiagnostics.cs
ATxDiagnostics/ATxDiagnostics.csproj
+1
-0
1 addition, 0 deletions
ATxDiagnostics/ATxDiagnostics.csproj
with
49 additions
and
1 deletion
ATxDiagnostics/ATxDiagnostics.cs
+
48
−
1
View file @
2eef7120
using
System
;
using
System.Management
;
using
ATxCommon
;
using
NLog
;
using
NLog.Config
;
...
...
@@ -15,13 +16,59 @@ namespace ATxDiagnostics
var
logTargetConsole
=
new
ConsoleTarget
{
Name
=
"console"
,
Header
=
"test-header"
,
Layout
=
@"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] (${logger}) ${message}"
,
};
logConfig
.
AddTarget
(
logTargetConsole
);
var
logRuleConsole
=
new
LoggingRule
(
"*"
,
LogLevel
.
Trace
,
logTargetConsole
);
logConfig
.
LoggingRules
.
Add
(
logRuleConsole
);
LogManager
.
Configuration
=
logConfig
;
Console
.
WriteLine
(
SystemChecks
.
WmiSummary
());
Log
.
Debug
(
Conv
.
BytesToString
(
SystemChecks
.
GetFreeDriveSpace
(
"C:"
)));
/*
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
Log.Debug(SystemChecks.GetCpuUsage());
*/
Log
.
Debug
(
QueryCpuLoad
());
}
private
static
int
QueryCpuLoad
()
{
Log
.
Trace
(
"Querying WMI for CPU load..."
);
var
searcher
=
new
ManagementObjectSearcher
(
"root\\CIMV2"
,
"select Name, PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor"
,
new
EnumerationOptions
{
Timeout
=
new
TimeSpan
(
0
,
0
,
10
),
ReturnImmediately
=
false
,
}
);
Int32
usageInt32
=
-
1
;
var
managementObjects
=
searcher
.
Get
();
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
);
Log
.
Trace
(
"CPU usage {1}: {0}"
,
usageInt32
,
name
);
//if (name.ToString().Equals("_Total")) {
// usageInt32 = Convert.ToInt32(usage);
// Log.Trace("CPU usage: {0}", usageInt32);
//}
}
managementObjects
.
Dispose
();
searcher
.
Dispose
();
return
usageInt32
;
}
}
}
This diff is collapsed.
Click to expand it.
ATxDiagnostics/ATxDiagnostics.csproj
+
1
−
0
View file @
2eef7120
...
...
@@ -44,6 +44,7 @@
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Management"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment