Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
monitoring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cylab
monitoring
Commits
cefd3f98
Commit
cefd3f98
authored
2 months ago
by
Tibo
Browse files
Options
Downloads
Patches
Plain Diff
don't trigger heartbeat agent for each new record, is way too heavygit add app/
parent
baa49c55
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#19717
failed
2 months ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/AgentScheduler.php
+23
-27
23 additions, 27 deletions
app/AgentScheduler.php
with
23 additions
and
27 deletions
app/AgentScheduler.php
+
23
−
27
View file @
cefd3f98
...
...
@@ -21,34 +21,34 @@ use Symfony\Component\Finder\SplFileInfo;
*/
class
AgentScheduler
{
/**
*
* @var LazyCollection<Sensor>
*/
private
$sensors
;
// associative array
// trigger_label => array<Sensor>
private
array
$triggers
;
private
function
__construct
()
{
$this
->
sensors
=
$this
->
autodiscover
();
$this
->
triggers
=
$this
->
register
(
$this
->
sensors
);
}
private
static
$instance
;
public
static
function
get
()
:
AgentScheduler
{
if
(
self
::
$instance
==
null
)
{
self
::
$instance
=
new
self
();
}
return
self
::
$instance
;
}
/**
*
* @return LazyCollection<Sensor>
...
...
@@ -57,7 +57,7 @@ class AgentScheduler
{
return
$this
->
sensors
;
}
/**
*
* @return LazyCollection<Sensor>
...
...
@@ -66,22 +66,22 @@ class AgentScheduler
{
$ROOT
=
__DIR__
.
"/Sensor/"
;
return
LazyCollection
::
make
(
File
::
allFiles
(
$ROOT
))
->
map
(
function
(
SplFileInfo
$file
)
{
$interface_name
=
"\App\Sensor"
;
$class_name
=
'\App\Sensor\\'
.
$file
->
getFilenameWithoutExtension
();
if
(
!
is_a
(
$class_name
,
$interface_name
,
true
))
{
return
;
}
$reflection
=
new
\ReflectionClass
(
$class_name
);
if
(
$reflection
->
isAbstract
())
{
return
;
}
return
new
$class_name
;
})
->
filter
();
}
/**
*
* @param LazyCollection<Sensor> $sensors
...
...
@@ -98,7 +98,7 @@ class AgentScheduler
}
return
$triggers
;
}
/**
* Get the list of defined agent labels.
*
...
...
@@ -110,42 +110,38 @@ class AgentScheduler
return
$sensor
->
config
()
->
label
;
})
->
toArray
();
}
// ------------------ SCHEDULING of agents
public
function
notify
(
Record
$record
)
{
$trigger_label
=
$record
->
label
;
if
(
!
isset
(
$this
->
triggers
[
$trigger_label
]))
{
return
;
}
foreach
(
$this
->
triggers
[
$trigger_label
]
as
$agent
)
{
/** @var Sensor $agent */
RunAgent
::
dispatch
(
$agent
,
$record
);
}
// special one : trigger heartbeat
$agent
=
new
Heartbeat
();
RunAgent
::
dispatch
(
$agent
,
$record
);
}
public
function
notifySummary
(
ReportSummary
$summary
)
{
(
new
StatusChangeDetector
())
->
analyze
(
$summary
);
}
public
function
notifyStatusChange
(
StatusChange
$change
)
{
(
new
Sensor\ChangeAlert
())
->
analyze
(
$change
);
}
public
function
notifyReport
(
Report
$report
)
{
$server
=
$report
->
server
;
$reports
=
$this
->
lastReportsOf
(
$server
);
$summary
=
new
ReportSummary
();
$summary
->
time
=
time
();
$summary
->
server_id
=
$server
->
id
;
...
...
@@ -153,7 +149,7 @@ class AgentScheduler
$summary
->
status_code
=
Status
::
max
(
$reports
)
->
code
();
$summary
->
save
();
}
/**
* Get the last report for each label.
*
...
...
@@ -167,7 +163,7 @@ class AgentScheduler
}
return
$reports
->
filter
();
}
public
function
lastReportOf
(
Server
$server
,
string
$label
)
:
?Report
{
$start
=
time
()
-
24
*
3600
;
...
...
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