Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9a6cda5e
Commit
9a6cda5e
authored
Feb 02, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added total queries monitoring
parent
a8007c8c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
3 deletions
+37
-3
Module.php
extensions/debug/Module.php
+2
-1
DbPanel.php
extensions/debug/panels/DbPanel.php
+16
-0
index.php
extensions/debug/views/default/index.php
+19
-2
No files found.
extensions/debug/Module.php
View file @
9a6cda5e
...
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\base\Application
;
use
yii\web\View
;
use
yii\web\ForbiddenHttpException
;
use
yii\helpers\ArrayHelper
;
/**
* The Yii Debug Module provides the debug toolbar and debugger
...
...
@@ -63,7 +64,7 @@ class Module extends \yii\base\Module
Yii
::
$app
->
getView
()
->
on
(
View
::
EVENT_END_BODY
,
[
$this
,
'renderToolbar'
]);
});
$this
->
panels
=
array_
merge
(
$this
->
corePanels
(),
$this
->
panels
);
$this
->
panels
=
ArrayHelper
::
merge
(
$this
->
corePanels
(),
$this
->
panels
);
foreach
(
$this
->
panels
as
$id
=>
$config
)
{
$config
[
'module'
]
=
$this
;
$config
[
'id'
]
=
$id
;
...
...
extensions/debug/panels/DbPanel.php
View file @
9a6cda5e
...
...
@@ -21,6 +21,11 @@ use yii\debug\models\search\Db;
class
DbPanel
extends
Panel
{
/**
*
* @var integer total queries critical count
*/
public
$criticalQueriesCount
;
/**
* @var array db queries info extracted to array as models, to use with data provider.
*/
private
$_models
;
...
...
@@ -147,4 +152,15 @@ class DbPanel extends Panel
preg_match
(
'/^([a-zA-z]*)/'
,
$timing
,
$matches
);
return
count
(
$matches
)
?
$matches
[
0
]
:
''
;
}
/**
* Check if given queries count is critical according settings.
* @param queries count $count
* @return boolean
*/
public
function
isQueriesCountCritical
(
$count
)
{
return
((
$this
->
criticalQueriesCount
!==
null
)
&&
(
$count
>
$this
->
criticalQueriesCount
));
}
}
extensions/debug/views/default/index.php
View file @
9a6cda5e
...
...
@@ -32,7 +32,9 @@ echo GridView::widget([
'dataProvider'
=>
$dataProvider
,
'filterModel'
=>
$searchModel
,
'rowOptions'
=>
function
(
$model
,
$key
,
$index
,
$grid
)
use
(
$searchModel
)
{
if
(
$searchModel
->
isCodeCritical
(
$model
[
'statusCode'
]))
{
$dbPanel
=
$this
->
context
->
module
->
panels
[
'db'
];
if
(
$searchModel
->
isCodeCritical
(
$model
[
'statusCode'
])
||
$dbPanel
->
isQueriesCountCritical
(
$model
[
'sqlCount'
]))
{
return
[
'class'
=>
'danger'
];
}
else
{
return
[];
...
...
@@ -58,7 +60,22 @@ echo GridView::widget([
'ip'
,
[
'attribute'
=>
'sqlCount'
,
'label'
=>
'Total queries count'
'label'
=>
'Total queries count'
,
'value'
=>
function
(
$data
)
{
$dbPanel
=
$this
->
context
->
module
->
panels
[
'db'
];
if
(
$dbPanel
->
isQueriesCountCritical
(
$data
[
'sqlCount'
]))
{
$content
=
Html
::
tag
(
'b'
,
$data
[
'sqlCount'
])
.
' '
.
Html
::
tag
(
'span'
,
''
,[
'class'
=>
'glyphicon glyphicon-exclamation-sign'
]);
return
Html
::
a
(
$content
,
$dbPanel
->
getUrl
(),
[
'title'
=>
'Query is slow. Allowed count is '
.
$dbPanel
->
criticalQueriesCount
,
]);
}
else
{
return
$data
[
'sqlCount'
];
}
},
'format'
=>
'html'
,
],
[
'attribute'
=>
'method'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment