Commit 9a6cda5e by Mark

added total queries monitoring

parent a8007c8c
......@@ -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,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));
}
}
......@@ -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',
......
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