Merge branch 'bugfix/lots-of-perfdata-160'

fixes #160
This commit is contained in:
Alexander A. Klimov 2018-04-06 16:37:52 +02:00
commit 3a98d2c473
6 changed files with 55 additions and 3 deletions

View file

@ -112,7 +112,10 @@ class ListController extends MonitoringAwareController
$dataView,
null,
null,
array_merge(['format', 'stateType', 'addColumns', 'problems'], TimeRangePicker::getAllRangeParameters())
array_merge(
['format', 'stateType', 'addColumns', 'problems', 'graphs_limit'],
TimeRangePicker::getAllRangeParameters()
)
);
$this->handleFormatRequest($dataView);
}

View file

@ -4,8 +4,8 @@
/** @var \Icinga\Application\Modules\MenuItemContainer $section */
$section = $this->menuSection(N_('Graphite'), ['icon' => 'chart-area']);
$section->add(N_('Hosts'), ['url' => 'graphite/list/hosts']);
$section->add(N_('Services'), ['url' => 'graphite/list/services']);
$section->add(N_('Hosts'), ['url' => 'graphite/list/hosts?graphs_limit=2']);
$section->add(N_('Services'), ['url' => 'graphite/list/services?graphs_limit=2']);
$this->provideConfigTab('backend', array(
'title' => $this->translate('Configure the Graphite Web backend'),

View file

@ -297,6 +297,33 @@ abstract class Graphs extends AbstractWidget
}
unset($graph);
$currentUrl = Icinga::app()->getRequest()->getUrl();
$limit = (int) $currentUrl->getParam('graphs_limit', 50);
$total = count($result);
if ($limit < 1) {
$limit = -1;
}
if ($limit !== -1 && $total > $limit) {
$result = array_slice($result, 0, $limit);
if (! $this->compact) {
/** @var View $view */
$view = $this->view();
$url = $this->getGraphsListBaseUrl();
TimeRangePickerTrait::copyAllRangeParameters($url->getParams(), $currentUrl->getParams());
$result[] = "<p class='load-more'>{$view->qlink(
sprintf($view->translate('Load all %d graphs'), $total),
$url->setParam('graphs_limit', '-1'),
null,
['class' => 'action-link']
)}</p>";
}
}
if ($this->maxVisibleGraphs && count($result) > $this->maxVisibleGraphs) {
/** @var View $view */
$view = $this->view();
@ -412,6 +439,13 @@ abstract class Graphs extends AbstractWidget
*/
abstract protected function getDummyImageBaseUrl();
/**
* Get the base URL to the monitored object's graphs list
*
* @return Url
*/
abstract protected function getGraphsListBaseUrl();
/**
* Extend the {@link getImageBaseUrl()}'s result's parameters with the concrete monitored object
*

View file

@ -40,6 +40,11 @@ class Host extends Graphs
return Url::fromPath('graphite/graph-dummy/host');
}
protected function getGraphsListBaseUrl()
{
return Url::fromPath('graphite/list/hosts', ['host' => $this->host]);
}
protected function filterImageUrl(Url $url)
{
return $url->setParam('host.name', $this->host);

View file

@ -49,6 +49,11 @@ class Service extends Graphs
return Url::fromPath('graphite/graph-dummy/service');
}
protected function getGraphsListBaseUrl()
{
return Url::fromPath('graphite/list/services', ['host' => $this->host, 'service' => $this->service]);
}
protected function filterImageUrl(Url $url)
{
return $url->setParam('host.name', $this->host)->setParam('service.name', $this->service);

View file

@ -114,3 +114,8 @@ form[name=form_timerangepickercustom_graphite] {
padding: .5em;
margin-bottom: 0;
}
p.load-more {
margin-right: 1em;
text-align: right;
}