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
5d64f8e5
Commit
5d64f8e5
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
validate wmi checks are working...
parent
e714c470
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ATxCommon/SystemChecks.cs
+78
-6
78 additions, 6 deletions
ATxCommon/SystemChecks.cs
ATxService/AutoTx.cs
+2
-1
2 additions, 1 deletion
ATxService/AutoTx.cs
with
80 additions
and
7 deletions
ATxCommon/SystemChecks.cs
+
78
−
6
View file @
5d64f8e5
...
...
@@ -15,7 +15,7 @@ namespace ATxCommon
/// <summary>
/// Get the available physical memory in MB.
/// </summary>
/// <returns>
The a
vailable physical memory in MB or -1 in case of an error.</returns>
/// <returns>
A
vailable physical memory in MB or -1 in case of an error.</returns>
public
static
long
GetFreeMemory
()
{
try
{
var
searcher
=
...
...
@@ -26,7 +26,7 @@ namespace ATxCommon
}
}
catch
(
Exception
ex
)
{
Log
.
Warn
(
"Error in GetFreeMemory: {0}"
,
ex
.
Message
);
Log
.
Trace
(
"Error in GetFreeMemory: {0}"
,
ex
.
Message
);
}
return
-
1
;
...
...
@@ -39,22 +39,94 @@ namespace ATxCommon
public
static
int
GetCpuUsage
()
{
// TODO: fix bug #36
try
{
Log
.
Trace
(
"Querying WMI for CPU load..."
);
var
searcher
=
new
ManagementObjectSearcher
(
"select * from Win32_PerfFormattedData_PerfOS_Processor"
);
foreach
(
var
mo
in
searcher
.
Get
())
{
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"];
if
(
name
.
ToString
().
Equals
(
"_Total"
))
return
Convert
.
ToInt32
(
usage
);
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);
}
}
return usageInt32;
*/
var
cpuTimes
=
searcher
.
Get
()
.
Cast
<
ManagementObject
>()
.
Select
(
mo
=>
new
{
Name
=
mo
[
"Name"
],
Usage
=
mo
[
"PercentProcessorTime"
]
}
)
.
ToList
();
if
(
cpuTimes
.
Count
==
0
)
return
-
1
;
Log
.
Trace
(
"WMI query returned {0} objects."
,
cpuTimes
.
Count
);
// The '_Total' value represents the average usage across all cores,
// and is the best representation of overall CPU usage
var
query
=
cpuTimes
.
Where
(
x
=>
x
.
Name
.
ToString
()
==
"_Total"
).
Select
(
x
=>
x
.
Usage
);
var
cpuUsage
=
query
.
SingleOrDefault
();
usageInt32
=
Convert
.
ToInt32
(
cpuUsage
);
Log
.
Trace
(
"CPU usage: {0}"
,
usageInt32
);
return
usageInt32
;
// */
}
catch
(
Exception
ex
)
{
Log
.
Warn
(
"Error in GetCpuUsage: {0}"
,
ex
.
Message
);
Log
.
Trace
(
"Error in GetCpuUsage: {0}"
,
ex
.
Message
);
}
Log
.
Trace
(
"Failed querying CPU usage!"
);
return
-
1
;
}
/// <summary>
/// Validate the WMI query methods work correctly and create a summary or warning message.
/// </summary>
/// <returns>A summary with current readings from WMI or a warning message.</returns>
public
static
string
WmiSummary
()
{
var
failed
=
new
List
<
string
>();
var
load
=
GetCpuUsage
();
var
free
=
GetFreeMemory
();
var
summary
=
$"CPU load:
{
load
}
\n"
+
$"Free system memory:
{
Conv
.
MegabytesToString
(
free
)}
\n"
;
Log
.
Warn
(
summary
);
if
(
load
==
-
1
)
{
failed
.
Add
(
"CPU load"
);
}
if
(
free
==
-
1
)
{
failed
.
Add
(
"free RAM"
);
}
if
(
failed
.
Count
>
0
)
{
summary
=
"*******************************************************\n"
+
"WARNING: Checking system parameters via WMI failed for:\n"
;
foreach
(
var
property
in
failed
)
{
summary
+=
$" -
{
property
}
\n"
;
}
summary
+=
"\n"
+
"-------------------------------------------------------\n"
+
"Limits configured for these properties will be IGNORED!\n"
+
"-------------------------------------------------------\n\n"
;
Log
.
Error
(
summary
);
}
return
summary
;
}
/// <summary>
/// Get the free space of a drive in bytes.
/// </summary>
...
...
This diff is collapsed.
Click to expand it.
ATxService/AutoTx.cs
+
2
−
1
View file @
5d64f8e5
...
...
@@ -338,7 +338,8 @@ namespace ATxService
msg
+=
"\n------ Current system parameters ------\n"
+
"Hostname: "
+
Environment
.
MachineName
+
"\n"
+
"Free system memory: "
+
SystemChecks
.
GetFreeMemory
()
+
" MB"
+
"\n"
;
SystemChecks
.
WmiSummary
();
foreach
(
var
driveToCheck
in
_config
.
SpaceMonitoring
)
{
msg
+=
"Free space on drive '"
+
driveToCheck
.
DriveName
+
"': "
+
Conv
.
BytesToString
(
SystemChecks
.
GetFreeDriveSpace
(
driveToCheck
.
DriveName
))
+
"\n"
;
...
...
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