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
e59ced61
Commit
e59ced61
authored
6 years ago
by
Tibo
Browse files
Options
Downloads
Patches
Plain Diff
Try to optimize mongo requests...
parent
0bcd1537
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
web/app/AbstractSensor.php
+20
-3
20 additions, 3 deletions
web/app/AbstractSensor.php
with
20 additions
and
3 deletions
web/app/AbstractSensor.php
+
20
−
3
View file @
e59ced61
...
...
@@ -26,10 +26,27 @@ abstract class AbstractSensor implements Sensor {
return
$this
->
server
->
lastRecordContaining
(
$field
);
}
/**
* Get the last $count records containing $field.
* !! $count is the MAXIMUM number of returned records.
* To optimize mongo's usage of index, we get the last $count records
* then filter locally for records containing this record
* @param type $field
* @param type $count
* @return type
*/
function
getLastRecords
(
$field
,
$count
)
{
return
\Mongo
::
get
()
->
monitoring
->
records
->
find
(
[
"server_id"
=>
$this
->
server
->
id
,
$field
=>
[
'$ne'
=>
null
]],
$records
=
\Mongo
::
get
()
->
monitoring
->
records
->
find
(
[
"server_id"
=>
$this
->
server
->
id
],
[
"limit"
=>
$count
,
"sort"
=>
[
"_id"
=>
-
1
]]);
$results
=
[];
foreach
(
$records
as
$record
)
{
if
(
isset
(
$record
->
$field
))
{
$results
[]
=
$record
;
}
}
return
$results
;
}
}
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