Commit a89d0db5 by Qiang Xue

Merge pull request #2282 from Ragazzo/debug_module_feature

added total queries monitoring
parents 81042fc1 47425145
......@@ -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;
......
......@@ -21,6 +21,12 @@ use yii\debug\models\search\Db;
class DbPanel extends Panel
{
/**
* @var integer the threshold for determining whether the request has involved
* critical number of DB queries. If the number of queries exceeds this number,
* the execution is considered taking critical number of DB queries.
*/
public $criticalQueryThreshold;
/**
* @var array db queries info extracted to array as models, to use with data provider.
*/
private $_models;
......@@ -147,4 +153,16 @@ 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 integer $count queries count
* @return boolean
*/
public function isQueryCountCritical($count)
{
return (($this->criticalQueryThreshold !== null) && ($count > $this->criticalQueryThreshold));
}
}
......@@ -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->isQueryCountCritical($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->isQueryCountCritical($data['sqlCount'])) {
$content = Html::tag('b', $data['sqlCount']) . ' ' . Html::tag('span','',['class' => 'glyphicon glyphicon-exclamation-sign']);
return Html::a($content, $dbPanel->getUrl(), [
'title' => 'Too many queries. Allowed count is ' . $dbPanel->criticalQueryThreshold,
]);
} else {
return $data['sqlCount'];
}
},
'format' => 'html',
],
[
'attribute' => 'method',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment