Fix perfdata output
Display all perfdata key-value pairs in a formatted table, add padding to table css improve piechart label.
This commit is contained in:
parent
e47eb73499
commit
b5747797b7
|
@ -24,21 +24,36 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||
$pieChartData = PerfdataSet::fromString($perfdataStr)->asArray();
|
||||
|
||||
$result = '';
|
||||
$table = array();
|
||||
$table = array(
|
||||
'<td><b>' . implode(
|
||||
'</b></td><td><b>',
|
||||
array('', t('Label'), t('Value'), t('Min'), t('Max'), t('Warning'), t('Critical'))
|
||||
) . '<b></td>'
|
||||
);
|
||||
foreach ($pieChartData as $perfdata) {
|
||||
if ($perfdata->isVisualizable()) {
|
||||
$pieChart = $perfdata->asInlinePie($color);
|
||||
if ($compact) {
|
||||
$result .= $pieChart->render();
|
||||
} else {
|
||||
$table[] = '<tr><th>' . $pieChart->render()
|
||||
. htmlspecialchars($perfdata->getLabel())
|
||||
. '</th><td> '
|
||||
. htmlspecialchars($this->formatPerfdataValue($perfdata)) .
|
||||
' </td></tr>';
|
||||
}
|
||||
|
||||
if ($compact && $perfdata->isVisualizable()) {
|
||||
$result .= $perfdata->asInlinePie($color)->render();
|
||||
} else {
|
||||
$table[] = (string)$perfdata;
|
||||
$row = '<tr>';
|
||||
|
||||
$row .= '<td>';
|
||||
if ($perfdata->isVisualizable()) {
|
||||
$row .= $perfdata->asInlinePie($color)->render() . ' ';
|
||||
}
|
||||
$row .= '</td>';
|
||||
|
||||
if (!$compact) {
|
||||
foreach ($perfdata->toArray() as $value) {
|
||||
if ($value === '') {
|
||||
$value = '-';
|
||||
}
|
||||
$row .= '<td>' . (string)$value . '</td>';
|
||||
}
|
||||
}
|
||||
|
||||
$row .= '</tr>';
|
||||
$table[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,18 +64,4 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
|
|||
return $pieCharts;
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatPerfdataValue(Perfdata $perfdata)
|
||||
{
|
||||
if ($perfdata->isBytes()) {
|
||||
return Format::bytes($perfdata->getValue());
|
||||
} elseif ($perfdata->isSeconds()) {
|
||||
return Format::seconds($perfdata->getValue());
|
||||
} elseif ($perfdata->isPercentage()) {
|
||||
return $perfdata->getValue() . '%';
|
||||
}
|
||||
|
||||
return $perfdata->getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Plugin;
|
||||
|
||||
use Icinga\Util\Format;
|
||||
use InvalidArgumentException;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Widget\Chart\InlinePie;
|
||||
|
@ -263,7 +264,7 @@ class Perfdata
|
|||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return sprintf(strpos($this->label, ' ') === false ? '%s=%s' : "'%s'=%s", $this->label, $this->perfdataValue);
|
||||
return $this->formatLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -294,11 +295,9 @@ class Perfdata
|
|||
$this->minValue = self::convert($parts[3], $this->unit);
|
||||
}
|
||||
case 3:
|
||||
// TODO(#6123): Tresholds have the same UOM and need to be converted as well!
|
||||
$this->criticalThreshold = trim($parts[2]) ? trim($parts[2]) : null;
|
||||
$this->criticalThreshold = trim($parts[2]) ? self::convert(trim($parts[2]), $this->unit) : null;
|
||||
case 2:
|
||||
// TODO(#6123): Tresholds have the same UOM and need to be converted as well!
|
||||
$this->warningThreshold = trim($parts[1]) ? trim($parts[1]) : null;
|
||||
$this->warningThreshold = trim($parts[1]) ? self::convert(trim($parts[1]), $this->unit) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,7 +369,7 @@ class Perfdata
|
|||
}
|
||||
|
||||
$data = $this->calculatePieChartData($color);
|
||||
$pieChart = new InlinePie($data, $this->getLabel() . ' ' . number_format($this->getPercentage(), 2) . '%');
|
||||
$pieChart = new InlinePie($data, $this);
|
||||
$pieChart->setSparklineClass('sparkline-perfdata');
|
||||
|
||||
if (Zend_Controller_Front::getInstance()->getRequest()->isXmlHttpRequest()) {
|
||||
|
@ -378,4 +377,51 @@ class Perfdata
|
|||
}
|
||||
return $pieChart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given value depending on the currently used unit
|
||||
*/
|
||||
protected function format($value)
|
||||
{
|
||||
if ($this->isPercentage()) {
|
||||
return (string)$value . '%';
|
||||
}
|
||||
if ($this->isBytes()) {
|
||||
return Format::bytes($value);
|
||||
}
|
||||
if ($this->isSeconds()) {
|
||||
return Format::seconds($value);
|
||||
}
|
||||
return number_format($value, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the title string that represents this perfdata set
|
||||
*
|
||||
* @param bool $html
|
||||
*
|
||||
* @return stringS
|
||||
*/
|
||||
public function formatLabel($html = false)
|
||||
{
|
||||
return sprintf(
|
||||
$html ? t('<b>%s %s</b> (%s%%)') : t('%s %s (%s%%)'),
|
||||
htmlspecialchars($this->getLabel()),
|
||||
$this->format($this->value),
|
||||
number_format($this->getPercentage(), 2)
|
||||
);
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$parts = array(
|
||||
$this->getLabel(),
|
||||
'value' => $this->format($this->getvalue()),
|
||||
'min' => isset($this->minValue) && !$this->isPercentage() ? $this->format($this->minValue) : '',
|
||||
'max' => isset($this->maxValue) && !$this->isPercentage() ? $this->format($this->maxValue) : '',
|
||||
'warn' => isset($this->warningThreshold) ? $this->format($this->warningThreshold) : '',
|
||||
'crit' => isset($this->criticalThreshold) ? $this->format($this->criticalThreshold) : ''
|
||||
);
|
||||
return $parts;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,6 +154,7 @@ table.perfdata th {
|
|||
|
||||
table.perfdata td {
|
||||
white-space: nowrap;
|
||||
padding-right: 0.5em;
|
||||
}
|
||||
|
||||
table.objectlist {
|
||||
|
|
Loading…
Reference in New Issue