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
2f95a64b
Commit
2f95a64b
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Raise events if CPU load status changes.
Refers to
#36
parent
eade424e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxCommon/Monitoring/Cpu.cs
+20
-3
20 additions, 3 deletions
ATxCommon/Monitoring/Cpu.cs
with
20 additions
and
3 deletions
ATxCommon/Monitoring/Cpu.cs
+
20
−
3
View file @
2f95a64b
...
...
@@ -12,6 +12,10 @@ namespace ATxCommon.Monitoring
{
private
static
readonly
Logger
Log
=
LogManager
.
GetCurrentClassLogger
();
public
delegate
void
EventHandler
(
object
sender
,
EventArgs
e
);
public
event
EventHandler
LoadAboveLimit
;
public
event
EventHandler
LoadBelowLimit
;
private
readonly
Timer
_monitoringTimer
;
private
readonly
PerformanceCounter
_cpuCounter
;
private
readonly
float
[]
_loadReadings
=
{
0F
,
0F
,
0F
,
0F
};
...
...
@@ -111,8 +115,8 @@ namespace ATxCommon.Monitoring
_load
=
_loadReadings
.
Average
();
if
(
_loadReadings
[
3
]
>
_limit
)
{
if
(
_behaving
>
_probation
)
{
// this means the load was considered as "low" before
// TODO: fire callback for violating load l
imit
// this means the load was considered as "low" before
, so raise an event:
OnLoadAboveL
imit
();
Log
.
Debug
(
"CPU load ({0}) violating limit ({1})!"
,
_loadReadings
[
3
],
_limit
);
}
else
if
(
_behaving
>
0
)
{
// this means we were still in probation, so no need to trigger again...
...
...
@@ -123,7 +127,7 @@ namespace ATxCommon.Monitoring
_behaving
++;
if
(
_behaving
==
_probation
)
{
Log
.
Debug
(
"CPU load below limit for {0} cycles, passing probation!"
,
_probation
);
// TODO: fire callback for load behaving well
OnLoadBelowLimit
();
}
else
if
(
_behaving
>
_probation
)
{
Log
.
Trace
(
"CPU load behaving well since {0} cycles."
,
_behaving
);
}
else
if
(
_behaving
<
0
)
{
...
...
@@ -142,5 +146,18 @@ namespace ATxCommon.Monitoring
_loadReadings
[
3
]
<
Limit
?
" ["
+
_behaving
+
"]"
:
""
);
}
/// <summary>
/// Raise the "LoadAboveLimit" event.
/// </summary>
protected
virtual
void
OnLoadAboveLimit
()
{
LoadAboveLimit
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
/// <summary>
/// Raise the "LoadBelowLimit" event.
/// </summary>
protected
virtual
void
OnLoadBelowLimit
()
{
LoadBelowLimit
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
}
}
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