mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-24 06:14:25 +02:00
monitoring/eventhistory: improve query performance
This takes care of timestamp columns, modifies queries in a way not depending on db functions, filters are passed through to subqueries for better performance.
This commit is contained in:
parent
6d7a1cfe08
commit
a904ff51aa
@ -136,9 +136,9 @@ class DbQuery extends SimpleQuery
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: render Filter (Where/like/time...)
|
|
||||||
$str .= $this->whereToSql($filter->getColumn(), $filter->getSign(), $filter->getExpression());
|
$str .= $this->whereToSql($filter->getColumn(), $filter->getSign(), $filter->getExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +165,12 @@ class DbQuery extends SimpleQuery
|
|||||||
return preg_replace('/\*/', '%', $value);
|
return preg_replace('/\*/', '%', $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function timestampForSql($value)
|
||||||
|
{
|
||||||
|
// TODO: do this db-aware
|
||||||
|
return $this->escapeForSql(date('Y-m-d H:i:s', $value));
|
||||||
|
}
|
||||||
|
|
||||||
public function whereToSql($col, $sign, $expression)
|
public function whereToSql($col, $sign, $expression)
|
||||||
{
|
{
|
||||||
if ($this->isTimestamp($col)) {
|
if ($this->isTimestamp($col)) {
|
||||||
|
@ -26,6 +26,15 @@ class CommentdeletionhistoryQuery extends IdoQuery
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function whereToSql($col, $sign, $expression)
|
||||||
|
{
|
||||||
|
if ($col === 'UNIX_TIMESTAMP(h.deletion_time)') {
|
||||||
|
return 'h.deletion_time ' . $sign . ' ' . $this->timestampForSql(strtotime($expression));
|
||||||
|
} else {
|
||||||
|
return parent::whereToSql($col, $sign, $expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
|
@ -26,6 +26,15 @@ class CommenthistoryQuery extends IdoQuery
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function whereToSql($col, $sign, $expression)
|
||||||
|
{
|
||||||
|
if ($col === 'UNIX_TIMESTAMP(h.comment_time)') {
|
||||||
|
return 'h.comment_time ' . $sign . ' ' . $this->timestampForSql(strtotime($expression));
|
||||||
|
} else {
|
||||||
|
return parent::whereToSql($col, $sign, $expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
|
@ -26,6 +26,15 @@ class DowntimeendhistoryQuery extends IdoQuery
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function whereToSql($col, $sign, $expression)
|
||||||
|
{
|
||||||
|
if ($col === 'UNIX_TIMESTAMP(h.actual_end_time)') {
|
||||||
|
return 'h.actual_end_time ' . $sign . ' ' . $this->timestampForSql(strtotime($expression));
|
||||||
|
} else {
|
||||||
|
return parent::whereToSql($col, $sign, $expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
|
@ -26,6 +26,15 @@ class DowntimestarthistoryQuery extends IdoQuery
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function whereToSql($col, $sign, $expression)
|
||||||
|
{
|
||||||
|
if ($col === 'UNIX_TIMESTAMP(h.actual_start_time)') {
|
||||||
|
return 'h.actual_start_time ' . $sign . ' ' . $this->timestampForSql(strtotime($expression));
|
||||||
|
} else {
|
||||||
|
return parent::whereToSql($col, $sign, $expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
use Zend_Db_Select;
|
use Zend_Db_Select;
|
||||||
|
|
||||||
class EventHistoryQuery extends IdoQuery
|
class EventHistoryQuery extends IdoQuery
|
||||||
@ -21,7 +22,6 @@ class EventHistoryQuery extends IdoQuery
|
|||||||
'service_description' => 'eho.name2 COLLATE latin1_general_ci',
|
'service_description' => 'eho.name2 COLLATE latin1_general_ci',
|
||||||
'object_type' => "CASE WHEN eho.objecttype_id = 1 THEN 'host' ELSE 'service' END",
|
'object_type' => "CASE WHEN eho.objecttype_id = 1 THEN 'host' ELSE 'service' END",
|
||||||
'timestamp' => 'eh.timestamp',
|
'timestamp' => 'eh.timestamp',
|
||||||
'raw_timestamp' => 'eh.raw_timestamp', // TODO: remove this as soon as removed from frontends
|
|
||||||
'state' => 'eh.state',
|
'state' => 'eh.state',
|
||||||
'attempt' => 'eh.attempt',
|
'attempt' => 'eh.attempt',
|
||||||
'max_attempts' => 'eh.max_attempts',
|
'max_attempts' => 'eh.max_attempts',
|
||||||
@ -40,7 +40,6 @@ class EventHistoryQuery extends IdoQuery
|
|||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$columns = array(
|
$columns = array(
|
||||||
'raw_timestamp',
|
|
||||||
'timestamp',
|
'timestamp',
|
||||||
'object_id',
|
'object_id',
|
||||||
'type',
|
'type',
|
||||||
@ -80,14 +79,22 @@ class EventHistoryQuery extends IdoQuery
|
|||||||
return parent::order($columnOrAlias, $dir);
|
return parent::order($columnOrAlias, $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function where($condition, $value = null)
|
public function addFilter(Filter $filter)
|
||||||
{
|
{
|
||||||
$this->requireColumn($condition);
|
foreach ($this->subQueries as $sub) {
|
||||||
foreach ($this->subQueries as $sub) {
|
$sub->applyFilter(clone $filter);
|
||||||
$sub->where($condition, $value);
|
}
|
||||||
}
|
return $this;
|
||||||
return $this;
|
}
|
||||||
}
|
|
||||||
|
public function where($condition, $value = null)
|
||||||
|
{
|
||||||
|
$this->requireColumn($condition);
|
||||||
|
foreach ($this->subQueries as $sub) {
|
||||||
|
$sub->where($condition, $value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function joinHostgroups()
|
protected function joinHostgroups()
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,15 @@ class NotificationhistoryQuery extends IdoQuery
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function whereToSql($col, $sign, $expression)
|
||||||
|
{
|
||||||
|
if ($col === 'UNIX_TIMESTAMP(n.start_time)') {
|
||||||
|
return 'n.start_time ' . $sign . ' ' . $this->timestampForSql(strtotime($expression));
|
||||||
|
} else {
|
||||||
|
return parent::whereToSql($col, $sign, $expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
switch ($this->ds->getDbType()) {
|
switch ($this->ds->getDbType()) {
|
||||||
|
@ -26,6 +26,15 @@ class StatehistoryQuery extends IdoQuery
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function whereToSql($col, $sign, $expression)
|
||||||
|
{
|
||||||
|
if ($col === 'UNIX_TIMESTAMP(sh.state_time)') {
|
||||||
|
return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql(strtotime($expression));
|
||||||
|
} else {
|
||||||
|
return parent::whereToSql($col, $sign, $expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function joinBaseTables()
|
protected function joinBaseTables()
|
||||||
{
|
{
|
||||||
$this->select->from(
|
$this->select->from(
|
||||||
|
@ -48,7 +48,6 @@ class EventHistory extends DataView
|
|||||||
'service_description',
|
'service_description',
|
||||||
'object_type',
|
'object_type',
|
||||||
'timestamp',
|
'timestamp',
|
||||||
'raw_timestamp',
|
|
||||||
'state',
|
'state',
|
||||||
'attempt',
|
'attempt',
|
||||||
'max_attempts',
|
'max_attempts',
|
||||||
@ -64,7 +63,7 @@ class EventHistory extends DataView
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'timestamp' => array(
|
'timestamp' => array(
|
||||||
'columns' => array('raw_timestamp'),
|
'columns' => array('timestamp'),
|
||||||
'order' => 'DESC'
|
'order' => 'DESC'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user