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
88b2b499
Commit
88b2b499
authored
1 year ago
by
Thibault Debatty
Browse files
Options
Downloads
Patches
Plain Diff
fix case where server has no report summary
parent
7b664f9d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#13349
failed
1 year ago
Stage: test
Stage: deploy
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/AgentScheduler.php
+26
-1
26 additions, 1 deletion
app/AgentScheduler.php
app/ReportSummary.php
+12
-0
12 additions, 0 deletions
app/ReportSummary.php
app/Server.php
+11
-33
11 additions, 33 deletions
app/Server.php
resources/views/server/show.blade.php
+0
-6
0 additions, 6 deletions
resources/views/server/show.blade.php
with
49 additions
and
40 deletions
app/AgentScheduler.php
+
26
−
1
View file @
88b2b499
...
...
@@ -6,6 +6,7 @@ use App\Jobs\RunAgent;
use
Illuminate\Support\Facades\File
;
use
Illuminate\Support\LazyCollection
;
use
Illuminate\Support\Collection
;
use
Symfony\Component\Finder\SplFileInfo
;
/**
...
...
@@ -125,7 +126,7 @@ class AgentScheduler
public
function
notifyReport
(
Report
$report
)
{
$server
=
$report
->
server
;
$reports
=
$
server
->
lastReports
(
);
$reports
=
$
this
->
lastReports
Of
(
$server
);
$summary
=
new
ReportSummary
();
$summary
->
time
=
time
();
...
...
@@ -134,4 +135,28 @@ class AgentScheduler
$summary
->
status_code
=
Status
::
max
(
$reports
)
->
code
();
$summary
->
save
();
}
/**
* Get the last report for each label.
*
* @return Collection<Report> last report for each label
*/
public
function
lastReportsOf
(
Server
$server
)
:
Collection
{
$reports
=
new
Collection
();
foreach
(
$this
->
agentLabel
()
as
$label
)
{
$reports
->
push
(
$this
->
lastReportOf
(
$server
,
$label
));
}
return
$reports
->
filter
();
}
public
function
lastReportOf
(
Server
$server
,
string
$label
)
:
?Report
{
$start
=
time
()
-
24
*
3600
;
return
$server
->
reports
()
->
where
(
"label"
,
$label
)
->
where
(
"time"
,
">"
,
$start
)
->
orderByDesc
(
"id"
)
->
first
();
}
}
This diff is collapsed.
Click to expand it.
app/ReportSummary.php
+
12
−
0
View file @
88b2b499
...
...
@@ -54,4 +54,16 @@ class ReportSummary extends Model
{
return
Carbon
::
createFromTimestamp
(
$this
->
time
);
}
public
static
function
default
(
Server
$server
)
:
ReportSummary
{
$summary
=
new
ReportSummary
();
$summary
->
server
=
$server
;
$summary
->
server_id
=
$server
->
id
;
$summary
->
time
=
0
;
$summary
->
status_code
=
-
1
;
$summary
->
reports
=
[];
return
$summary
;
}
}
This diff is collapsed.
Click to expand it.
app/Server.php
+
11
−
33
View file @
88b2b499
...
...
@@ -105,13 +105,6 @@ class Server extends Model
->
get
();
}
public
function
hasData
()
:
bool
{
return
true
;
//return false;
//return $this->lastRecord() != null;
}
public
function
info
()
:
ServerInfo
{
if
(
is_null
(
$this
->
info
))
{
...
...
@@ -133,6 +126,7 @@ class Server extends Model
public
function
getSensorsNOK
()
:
Collection
{
$summary
=
$this
->
lastSummary
();
if
(
$summary
->
status_code
==
0
)
{
return
new
Collection
();
}
...
...
@@ -150,30 +144,6 @@ class Server extends Model
}
/**
* Get the last report for each label.
*
* @return Collection<Report> last report for each label
*/
public
function
lastReports
()
{
$reports
=
new
Collection
();
foreach
(
AgentScheduler
::
get
()
->
agentLabel
()
as
$label
)
{
$reports
->
push
(
$this
->
lastReport
(
$label
));
}
return
$reports
->
filter
();
}
public
function
lastReport
(
string
$label
)
:
?Report
{
$start
=
time
()
-
24
*
3600
;
return
$this
->
reports
()
->
where
(
"label"
,
$label
)
->
where
(
"time"
,
">"
,
$start
)
->
orderByDesc
(
"id"
)
->
first
();
}
public
function
summaries
()
{
return
$this
->
hasMany
(
ReportSummary
::
class
);
...
...
@@ -183,10 +153,18 @@ class Server extends Model
public
function
lastSummary
()
:
ReportSummary
{
if
(
is_null
(
$this
->
last_summary
))
{
$this
->
last_summary
=
$this
->
summaries
()
->
orderByDesc
(
"id"
)
->
first
();
if
(
!
is_null
(
$this
->
last_summary
))
{
return
$this
->
last_summary
;
}
// try to fetch from DB
$summary
=
$this
->
summaries
()
->
orderByDesc
(
"id"
)
->
first
();
if
(
!
is_null
(
$summary
))
{
$this
->
last_summary
=
$summary
;
return
$this
->
last_summary
;
}
$this
->
last_summary
=
ReportSummary
::
default
(
$this
);
return
$this
->
last_summary
;
}
...
...
This diff is collapsed.
Click to expand it.
resources/views/server/show.blade.php
+
0
−
6
View file @
88b2b499
...
...
@@ -17,7 +17,6 @@ window.monitorServerToken = "{{ $server->read_token }}";
<
div
class
=
"card"
>
<
div
class
=
"card-body"
>
@
if
(
$server
->
hasData
())
<
p
>
{
!!
$server
->
status
()
->
badge
()
!!
}
{{
$server
->
lastSummary
()
->
time
()
->
toDateTimeString
()
}}
...
...
@@ -45,11 +44,6 @@ window.monitorServerToken = "{{ $server->read_token }}";
</
p
>
<
p
>
Uptime
:
{{
$server
->
info
()
->
uptime
()
}}
</
p
>
@
else
<
p
>
No
information
to
show
for
now
...
</
p
>
@
endif
</
div
>
</
div
>
...
...
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