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
82a9ed8f
Commit
82a9ed8f
authored
6 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Adapt ATxDiagnostics to show multiple performance monitors
Fixes
#53
parent
cf07428f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxDiagnostics/ATxDiagnostics.cs
+30
-55
30 additions, 55 deletions
ATxDiagnostics/ATxDiagnostics.cs
with
30 additions
and
55 deletions
ATxDiagnostics/ATxDiagnostics.cs
+
30
−
55
View file @
82a9ed8f
using
System
;
using
System.Diagnostics
;
using
System.Management
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Reflection
;
using
ATxCommon
;
using
ATxCommon.Monitoring
;
...
...
@@ -30,67 +29,43 @@ namespace ATxDiagnostics
logConfig
.
LoggingRules
.
Add
(
logRuleConsole
);
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
);
Log
.
Info
(
"ATxCommon library version: {0}"
,
commonVersionInfo
.
ProductVersion
);
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..."
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
WmiQueryCpuLoad
();
System
.
Threading
.
Thread
.
Sleep
(
1000
);
if
(
perfMonitors
.
Contains
(
"CPU"
))
{
Log
.
Info
(
"Watching CPU load using ATxCommon.Monitoring..."
);
var
cpu
=
new
Cpu
{
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
);
Log
.
Debug
(
"CPU usage {1}: {0}"
,
usageInt32
,
name
);
}
}
else
{
Log
.
Error
(
"No objects returned from WMI!"
);
if
(
perfMonitors
.
Contains
(
"PhysicalDisk"
))
{
Log
.
Info
(
"Watching I/O load using ATxCommon.Monitoring..."
);
var
disk
=
new
PhysicalDisk
{
Interval
=
250
,
Limit
=
0.25F
,
Probation
=
4
,
// 4 * 250 ms = 1 second
LogPerformanceReadings
=
LogLevel
.
Info
,
Enabled
=
true
};
}
managementObjects
.
Dispose
();
searcher
.
Dispose
();
watch
.
Stop
();
Log
.
Trace
(
"WMI query took {0} ms."
,
watch
.
ElapsedMilliseconds
);
return
usageInt32
;
while
(
true
)
{
System
.
Threading
.
Thread
.
Sleep
(
10000
);
}
}
}
}
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