public function testCreateGraphPanel() { define('INFLUXDB', 'influxdb'); define('ELASTICSEARCH', 'elasticsearch'); define('SHOW_LEGEND', false); define("DATABASE_TYPE", 'foo'); define("ELASTICSEARCH_INDEX", 'bar'); $this->setExpectedException('\\InvalidArgumentException'); $d = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel('d1'); }
public function testCreateGraphPanelElasticsearch() { define('INFLUXDB', 'influxdb'); define('ELASTICSEARCH', 'elasticsearch'); define('SHOW_LEGEND', false); define("DATABASE_TYPE", ELASTICSEARCH); define("ELASTICSEARCH_INDEX", 'nagflux'); $gpanel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel('gpanel'); $this->assertSame('gpanel', $gpanel->toArray()['title']); $t1 = $gpanel->genTargetSimple('h2', 's1', 'c1', 'p1'); $this->assertSame('host: "h2" AND service: "s1" AND command: "c1" AND performanceLabel: "p1"', $t1['query']); $this->assertSame(ELASTICSEARCH_INDEX, $t1['datasource']); $this->assertSame('p1-{{field}}', $t1['alias']); $this->assertSame(1, sizeof($t1['metrics'])); $t2 = $gpanel->addWarnToTarget($t1); $this->assertSame(4, sizeof($t2['metrics'])); $this->assertSame('value', $t2['metrics'][0]['field']); $this->assertSame('warn', $t2['metrics'][1]['field']); $this->assertSame('warn-min', $t2['metrics'][2]['field']); $this->assertSame('warn-max', $t2['metrics'][3]['field']); $t3 = $gpanel->addWarnToTarget($t1, '', false); $this->assertSame(4, sizeof($t2['metrics'])); $this->assertSame('value', $t2['metrics'][0]['field']); $this->assertSame('warn', $t2['metrics'][1]['field']); $this->assertSame('warn-min', $t2['metrics'][2]['field']); $this->assertSame('warn-max', $t2['metrics'][3]['field']); $t4 = $gpanel->addCritToTarget($t1); $this->assertSame(4, sizeof($t4['metrics'])); $this->assertSame('value', $t4['metrics'][0]['field']); $this->assertSame('crit', $t4['metrics'][1]['field']); $this->assertSame('crit-min', $t4['metrics'][2]['field']); $this->assertSame('crit-max', $t4['metrics'][3]['field']); $t5 = $gpanel->addCritToTarget($t1, '', false); $this->assertSame(4, sizeof($t5['metrics'])); $this->assertSame('value', $t5['metrics'][0]['field']); $this->assertSame('crit', $t5['metrics'][1]['field']); $this->assertSame('crit-min', $t5['metrics'][2]['field']); $this->assertSame('crit-max', $t5['metrics'][3]['field']); $d1 = $gpanel->genDowntimeTarget('h1', 's1', 'c1', 'p1'); $this->assertSame('downtime', $d1['alias']); $this->assertSame('host: "h1" AND service: "s1" AND command: "c1" AND performanceLabel: "p1" AND downtime: "true"', $d1['query']); try { $d1 = $gpanel->genForecastTarget('h1', 's1', 'c1', 'p1'); } catch (\Exception $e) { $this->assertEquals("Not implemented", $e->getMessage()); } }
public function testToArrayInfluxdb() { define("INFLUXDB_DB", 'nagflux'); define("DATABASE_TYPE", 'influxdb'); define('INFLUXDB', 'influxdb'); define('ELASTICSEARCH', 'elasticsearch'); define('HEIGHT', '100'); define('SHOW_LEGEND', true); define('FORECAST_DATASOURCE_NAME', "nagflux_forecast"); $d = \histou\grafana\dashboard\DashboardFactory::generateDashboard('d'); $row = new \histou\grafana\Row("r"); $gpanel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel("p"); \histou\template\ForecastTemplate::$config = array('size' => array('method' => 'SimpleLinearRegression', 'forecast' => '20m'), 'time' => array('method' => 'SimpleLinearRegression', 'forecast' => '30m')); $target = $gpanel->genForecastTarget('host', 'service', 'command', 'size', '000', '', true, true); $target = $gpanel->genForecastTarget('host', 'service', 'command', 'time', '000', '', true, true); $a = $d->toArray(); $expected = array('id' => '1', 'title' => 'd', 'originalTitle' => 'CustomDashboard', 'tags' => array(), 'timezone' => 'browser', 'editable' => true, 'hideControls' => true, 'sharedCrosshair' => false, 'nav' => array(array('type' => 'timepicker', 'enable' => true, 'time_options' => array(0 => '5m', 1 => '15m', 2 => '1h', 3 => '6h', 4 => '12h', 5 => '24h', 6 => '2d', 7 => '7d', 8 => '30d'), 'refresh_intervals' => array(0 => '5s', 1 => '10s', 2 => '30s', 3 => '1m', 4 => '5m', 5 => '15m', 6 => '30m', 7 => '1h', 8 => '2h', 9 => '1d'), 'now' => true, 'collapse' => false, 'notice' => false)), 'time' => array('from' => 'now-8h', 'to' => 'now+30m'), 'templating' => array('list' => array()), 'annotations' => array('enable' => true, 'list' => array()), 'refresh' => '30s', 'version' => '6', 'rows' => array()); $this->assertSame($expected, $a); }
$dashboard->addDefaultAnnotations($perfData['host'], $perfData['service']); $templateName = 'Database'; $dashboard->addTemplateForPerformanceLabel($templateName, $perfData['host'], $perfData['service'], $regex = '^db_(.*?)_log_free$', $multiFormat = true, $includeAll = false); $tempalteVariableString = $dashboard->genTemplateVariable($templateName); $database = ""; foreach ($perfData['perfLabel'] as $key => $value) { if (preg_match(';^db_(.*?)_log_free$;', $key, $hit)) { $database = $key; break; } } $types = array('pct' => array("free_pct", "allocated_pct", "log_free_pct", "log_allocated_pct"), 'fix' => array("free", "log_free")); $numberPanels = 0; $row = new \histou\grafana\Row($perfData['service'] . ' ' . $perfData['command']); foreach ($types as $type => $labels) { $panel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel($perfData['service'] . " {$tempalteVariableString} " . $type); $panel->setSpan(6); if ($type == 'fix' && isset($perfData['perfLabel'][$database]['unit'])) { $panel->setLeftUnit($perfData['perfLabel'][$database]['unit']); } elseif ($type == 'pct') { $panel->setLeftUnit('%'); } $currentColorIndex = 0; foreach ($labels as $label) { if (DATABASE_TYPE == ELASTICSEARCH) { //https://github.com/grafana/grafana/issues/4075 $perfLabel = "db_" . $tempalteVariableString . "\\_" . $label; } else { $perfLabel = "db_" . $tempalteVariableString . "_" . $label; } $target = $panel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], $perfLabel);
$suiteStat = \histou\grafana\singlestatpanel\SinglestatPanelFactory::generatePanel(""); $suiteStat->setSpan(1); $suiteStat->addTarget($suiteStat->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], 'suite__state')); $suiteStat->setColor(array('#99ff66', '#ffc125', '#ee0000')); $suiteStat->setThresholds("1", "2"); $suiteStat->addRangeToTextElement(0, 0.5, 'OK'); $suiteStat->addRangeToTextElement(0.5, 1.5, 'Warn'); $suiteStat->addRangeToTextElement(1.5, 2.5, 'Crit'); $suiteStat->addRangeToTextElement(2.5, 3.5, 'Unkn'); $suiteRow->addPanel($suiteStat); $dashboard->addRow($suiteRow); //Case Row $caseRow = new \histou\grafana\Row("Case-Runtime"); $caseRow->setCustomProperty("repeat", $templateName); //Case Graph Panel $casePanel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel($perfData['service'] . " (Sakuli case #{$templateVariableString}) on " . $perfData['host']); $casePanel->setLeftUnit("s"); $casePanel->setSpan(11); $casePanel->setLeftYAxisMinMax(0); $casePanel->fillBelowLine("/^(?!warning|critical).*\$/", 5); $casePanel->setLegend(true, true, true, true, false, false, true, true, true, true); $target1 = $casePanel->createTarget(array('host' => array('value' => $perfData['host'], 'operator' => '='), 'service' => array('value' => $perfData['service'], 'operator' => '='), 'command' => array('value' => $perfData['command'], 'operator' => '='), 'performanceLabel' => array('value' => \histou\helper\str::genRegex('c_' . $templateVariableString . '_[^_].*'), 'operator' => '=~'))); $target1 = $casePanel->addXToTarget($target1, array('value'), '', ''); $target1['alias'] = '$tag_performanceLabel'; $target1['groupBy'] = array(array("params" => array("\$interval"), "type" => "time"), array("params" => array("performanceLabel"), "type" => "tag"), array("params" => array("null"), "type" => "fill")); $casePanel->addTarget($target1); $target = $casePanel->createTarget(array('host' => array('value' => $perfData['host'], 'operator' => '='), 'service' => array('value' => $perfData['service'], 'operator' => '='), 'command' => array('value' => $perfData['command'], 'operator' => '='), 'performanceLabel' => array('value' => \histou\helper\str::genRegex('s_' . $templateVariableString . '.*'), 'operator' => '=~'))); $target = $casePanel->addXToTarget($target, array('value'), '', ''); $target['alias'] = '$tag_performanceLabel'; $target['groupBy'] = array(array("params" => array("\$interval"), "type" => "time"), array("params" => array("performanceLabel"), "type" => "tag"), array("params" => array("null"), "type" => "fill")); $casePanel->addTarget($target);
public function testGraphPanelInfluxdbSetLegend() { $this->init(); $gpanel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel('gpanel'); $gpanel->setLegend(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $this->assertSame(array('show' => 1, 'values' => 2, 'min' => 3, 'max' => 4, 'current' => 5, 'total' => 6, 'avg' => 7, 'alignAsTable' => 8, 'rightSide' => 9, 'hideEmpty' => 10), $gpanel->toArray()['legend']); }
Template for the icinga2 self check. PHP version 5 @category Template_File @package Histou/templates/default @author Philip Griesbacher <*****@*****.**> @license http://opensource.org/licenses/gpl-license.php GNU Public License @link https://github.com/Griesbacher/histou **/ $rule = new \histou\template\Rule($host = '.*', $service = '.*', $command = '^icinga$', $perfLabel = array('.*')); $genTemplate = function ($perfData) { $colors = array("#7EB26D", "#EAB839", "#6ED0E0", "#1F78C1", "#BA43A9", "#508642", "#CCA300", "#447EBC", "#C15C17"); $dashboard = \histou\grafana\dashboard\DashboardFactory::generateDashboard($perfData['host'] . '-' . $perfData['service']); $dashboard->addDefaultAnnotations($perfData['host'], $perfData['service']); $genRow = function ($panelName, array $perfLabelparts, $perfLabelformat) use($perfData, $colors, $dashboard) { $row = new \histou\grafana\Row($perfData['service'] . ' ' . $perfData['command']); $panel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel($perfData['host'] . ' ' . $perfData['service'] . ' ' . $perfData['command'] . ' ' . $panelName); $i = 0; foreach ($perfLabelparts as $part) { $perfLabel = sprintf($perfLabelformat, $part); $target = $panel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], $perfLabel, $colors[$i++]); $panel->addTarget($target); } $row->addPanel($panel); $dashboard->addRow($row); }; foreach (array('active_host_checks', 'passive_host_checks', 'active_service_checks', 'passive_service_checks') as $checks) { $genRow($checks, array('', '_1min', '_5min', '_15min'), $checks . '%s'); } foreach (array('latency', 'execution_time') as $type) { $genRow($type, array('min', 'max', 'avg'), '%s_' . $type); }
foreach ($overviewData as $label => $data) { $statesPanel->addTarget($statesPanel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], "check_multi_extended::check_multi_extended::{$label}", $data[0], $data[1])); } $statesPanel->addTarget($statesPanel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], "check_multi::check_multi::plugins", '#085DFF', "Plugins")); $statesPanel->setSpan(11); $statesPanel->setLeftYAxisMinMax(0); $statesRow->addPanel($statesPanel); $overallState = \histou\grafana\singlestatpanel\SinglestatPanelFactory::generatePanel(""); $overallState->setSpan(1); $overallState->addTarget($overallState->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], 'check_multi_extended::check_multi_extended::overall_state')); $overallState->setColor(array('#99ff66', '#ffc125', '#ee0000')); $overallState->setThresholds("1", "2"); $overallState->addRangeToTextElement(0, 0.5, 'OK'); $overallState->addRangeToTextElement(0.5, 1.5, 'Warn'); $overallState->addRangeToTextElement(1.5, 2.5, 'Crit'); $overallState->addRangeToTextElement(2.5, 3.5, 'Unkn'); $statesRow->addPanel($overallState); $dashboard->addRow($statesRow); $row = new \histou\grafana\Row($tempalteVariableStringPerfLabel); $panel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel($tempalteVariableStringPerfLabel); $target = $panel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], $tempalteVariableStringPerfLabel); $target = $panel->addWarnToTarget($target, $tempalteVariableStringPerfLabel); $target = $panel->addCritToTarget($target, $tempalteVariableStringPerfLabel); $panel->addTarget($target); $downtime = $panel->genDowntimeTarget($perfData['host'], $perfData['service'], $perfData['command'], $tempalteVariableStringPerfLabel); $panel->addTarget($downtime); $row->addPanel($panel); $row->setCustomProperty("repeat", $templateNamePerfLabel); $dashboard->addRow($row); return $dashboard; };