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
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;
...
@@ -21,34 +21,34 @@ use Symfony\Component\Finder\SplFileInfo;
*/
*/
class
AgentScheduler
class
AgentScheduler
{
{
/**
/**
*
*
* @var LazyCollection<Sensor>
* @var LazyCollection<Sensor>
*/
*/
private
$sensors
;
private
$sensors
;
// associative array
// associative array
// trigger_label => array<Sensor>
// trigger_label => array<Sensor>
private
array
$triggers
;
private
array
$triggers
;
private
function
__construct
()
private
function
__construct
()
{
{
$this
->
sensors
=
$this
->
autodiscover
();
$this
->
sensors
=
$this
->
autodiscover
();
$this
->
triggers
=
$this
->
register
(
$this
->
sensors
);
$this
->
triggers
=
$this
->
register
(
$this
->
sensors
);
}
}
private
static
$instance
;
private
static
$instance
;
public
static
function
get
()
:
AgentScheduler
public
static
function
get
()
:
AgentScheduler
{
{
if
(
self
::
$instance
==
null
)
{
if
(
self
::
$instance
==
null
)
{
self
::
$instance
=
new
self
();
self
::
$instance
=
new
self
();
}
}
return
self
::
$instance
;
return
self
::
$instance
;
}
}
/**
/**
*
*
* @return LazyCollection<Sensor>
* @return LazyCollection<Sensor>
...
@@ -57,7 +57,7 @@ class AgentScheduler
...
@@ -57,7 +57,7 @@ class AgentScheduler
{
{
return
$this
->
sensors
;
return
$this
->
sensors
;
}
}
/**
/**
*
*
* @return LazyCollection<Sensor>
* @return LazyCollection<Sensor>
...
@@ -66,22 +66,22 @@ class AgentScheduler
...
@@ -66,22 +66,22 @@ class AgentScheduler
{
{
$ROOT
=
__DIR__
.
"/Sensor/"
;
$ROOT
=
__DIR__
.
"/Sensor/"
;
return
LazyCollection
::
make
(
File
::
allFiles
(
$ROOT
))
->
map
(
function
(
SplFileInfo
$file
)
{
return
LazyCollection
::
make
(
File
::
allFiles
(
$ROOT
))
->
map
(
function
(
SplFileInfo
$file
)
{
$interface_name
=
"\App\Sensor"
;
$interface_name
=
"\App\Sensor"
;
$class_name
=
'\App\Sensor\\'
.
$file
->
getFilenameWithoutExtension
();
$class_name
=
'\App\Sensor\\'
.
$file
->
getFilenameWithoutExtension
();
if
(
!
is_a
(
$class_name
,
$interface_name
,
true
))
{
if
(
!
is_a
(
$class_name
,
$interface_name
,
true
))
{
return
;
return
;
}
}
$reflection
=
new
\ReflectionClass
(
$class_name
);
$reflection
=
new
\ReflectionClass
(
$class_name
);
if
(
$reflection
->
isAbstract
())
{
if
(
$reflection
->
isAbstract
())
{
return
;
return
;
}
}
return
new
$class_name
;
return
new
$class_name
;
})
->
filter
();
})
->
filter
();
}
}
/**
/**
*
*
* @param LazyCollection<Sensor> $sensors
* @param LazyCollection<Sensor> $sensors
...
@@ -98,7 +98,7 @@ class AgentScheduler
...
@@ -98,7 +98,7 @@ class AgentScheduler
}
}
return
$triggers
;
return
$triggers
;
}
}
/**
/**
* Get the list of defined agent labels.
* Get the list of defined agent labels.
*
*
...
@@ -110,42 +110,38 @@ class AgentScheduler
...
@@ -110,42 +110,38 @@ class AgentScheduler
return
$sensor
->
config
()
->
label
;
return
$sensor
->
config
()
->
label
;
})
->
toArray
();
})
->
toArray
();
}
}
// ------------------ SCHEDULING of agents
// ------------------ SCHEDULING of agents
public
function
notify
(
Record
$record
)
public
function
notify
(
Record
$record
)
{
{
$trigger_label
=
$record
->
label
;
$trigger_label
=
$record
->
label
;
if
(
!
isset
(
$this
->
triggers
[
$trigger_label
]))
{
if
(
!
isset
(
$this
->
triggers
[
$trigger_label
]))
{
return
;
return
;
}
}
foreach
(
$this
->
triggers
[
$trigger_label
]
as
$agent
)
{
foreach
(
$this
->
triggers
[
$trigger_label
]
as
$agent
)
{
/** @var Sensor $agent */
/** @var Sensor $agent */
RunAgent
::
dispatch
(
$agent
,
$record
);
RunAgent
::
dispatch
(
$agent
,
$record
);
}
}
// special one : trigger heartbeat
$agent
=
new
Heartbeat
();
RunAgent
::
dispatch
(
$agent
,
$record
);
}
}
public
function
notifySummary
(
ReportSummary
$summary
)
public
function
notifySummary
(
ReportSummary
$summary
)
{
{
(
new
StatusChangeDetector
())
->
analyze
(
$summary
);
(
new
StatusChangeDetector
())
->
analyze
(
$summary
);
}
}
public
function
notifyStatusChange
(
StatusChange
$change
)
public
function
notifyStatusChange
(
StatusChange
$change
)
{
{
(
new
Sensor\ChangeAlert
())
->
analyze
(
$change
);
(
new
Sensor\ChangeAlert
())
->
analyze
(
$change
);
}
}
public
function
notifyReport
(
Report
$report
)
public
function
notifyReport
(
Report
$report
)
{
{
$server
=
$report
->
server
;
$server
=
$report
->
server
;
$reports
=
$this
->
lastReportsOf
(
$server
);
$reports
=
$this
->
lastReportsOf
(
$server
);
$summary
=
new
ReportSummary
();
$summary
=
new
ReportSummary
();
$summary
->
time
=
time
();
$summary
->
time
=
time
();
$summary
->
server_id
=
$server
->
id
;
$summary
->
server_id
=
$server
->
id
;
...
@@ -153,7 +149,7 @@ class AgentScheduler
...
@@ -153,7 +149,7 @@ class AgentScheduler
$summary
->
status_code
=
Status
::
max
(
$reports
)
->
code
();
$summary
->
status_code
=
Status
::
max
(
$reports
)
->
code
();
$summary
->
save
();
$summary
->
save
();
}
}
/**
/**
* Get the last report for each label.
* Get the last report for each label.
*
*
...
@@ -167,7 +163,7 @@ class AgentScheduler
...
@@ -167,7 +163,7 @@ class AgentScheduler
}
}
return
$reports
->
filter
();
return
$reports
->
filter
();
}
}
public
function
lastReportOf
(
Server
$server
,
string
$label
)
:
?Report
public
function
lastReportOf
(
Server
$server
,
string
$label
)
:
?Report
{
{
$start
=
time
()
-
24
*
3600
;
$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