public function testCreateElesticsearchGraphPanel() { define('INFLUXDB', 'influxdb'); define('ELASTICSEARCH', 'elasticsearch'); define('SHOW_LEGEND', false); define("DATABASE_TYPE", 'elasticsearch'); define("ELASTICSEARCH_INDEX", 'bar'); $this->setExpectedException('\\InvalidArgumentException'); $d = \histou\grafana\singlestatpanel\SinglestatPanelFactory::generatePanel('d1'); }
public function testGenTargetSimplePanelInfluxdb() { $this->init(); $spanel = \histou\grafana\singlestatpanel\SinglestatPanelFactory::generatePanel('spanel'); $target = $spanel->genTargetSimple("host", "service", "command", "perflabel"); $expected = array('measurement' => 'metrics', 'alias' => '$col', 'select' => array(array(array('type' => 'field', 'params' => array('value')), array('type' => 'last', 'params' => array()))), 'tags' => array(array('key' => 'host', 'operator' => '=', 'value' => 'host'), array('condition' => 'AND', 'key' => 'service', 'operator' => '=', 'value' => 'service'), array('condition' => 'AND', 'key' => 'command', 'operator' => '=', 'value' => 'command'), array('condition' => 'AND', 'key' => 'performanceLabel', 'operator' => '=', 'value' => 'perflabel')), 'dsType' => 'influxdb', 'resultFormat' => 'time_series', 'datasource' => 'nagflux', 'groupBy' => array()); $this->assertSame($expected, $target); $rtarget = $spanel->genTargetSimple("host", "service", "command", "perflabel", true); $rexpected = array('measurement' => 'metrics', 'alias' => '$col', 'select' => array(array(array('type' => 'field', 'params' => array('value')), array('type' => 'last', 'params' => array()))), 'tags' => array(array('key' => 'host', 'operator' => '=~', 'value' => '/^host$/'), array('condition' => 'AND', 'key' => 'service', 'operator' => '=~', 'value' => '/^service$/'), array('condition' => 'AND', 'key' => 'command', 'operator' => '=~', 'value' => '/^command$/'), array('condition' => 'AND', 'key' => 'performanceLabel', 'operator' => '=~', 'value' => '/^perflabel$/')), 'dsType' => 'influxdb', 'resultFormat' => 'time_series', 'datasource' => 'nagflux', 'groupBy' => array()); $this->assertSame($rexpected, $rtarget); }
$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); $casePanel->stack('/s_\\d\\d\\d_.*/'); $casePanel->addTarget($casePanel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], "c_{$templateVariableString}" . "__warning", '#FFFC15', 'warning')); $casePanel->addTarget($casePanel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], "c_{$templateVariableString}" . "__critical", '#FF3727', 'critical')); $c = 0; for ($i = 0; $i < $maxSteps; $i++) { $casePanel->addRegexColor(sprintf('/s_\\d\\d\\d_%03d_.*/', $i), $stepColors[$c]); $c = ($c + 1) % (sizeof($stepColors) - 1); } $caseRow->addPanel($casePanel); //Case Stat Panel $caseStat = \histou\grafana\singlestatpanel\SinglestatPanelFactory::generatePanel(""); $caseStat->setSpan(1); $caseStat->addTarget($caseStat->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], "c_{$templateVariableString}" . '__state')); $caseStat->setColor(array('#99ff66', '#ffc125', '#ee0000')); $caseStat->setThresholds("1", "2"); $caseStat->addRangeToTextElement(0, 0.5, 'OK'); $caseStat->addRangeToTextElement(0.5, 1.5, 'Warn'); $caseStat->addRangeToTextElement(1.5, 2.5, 'Crit'); $caseStat->addRangeToTextElement(2.5, 3.5, 'Unkn'); $caseRow->addPanel($caseStat); $dashboard->addRow($caseRow); return $dashboard; };
if (preg_match(';^db_(.*?)_log_free$;', $key, $hit)) { $database = $key; break; } } $statesRow = new \histou\grafana\Row("Overallstate", "200px"); $statesPanel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel("check_multi overview"); $overviewData = array('count_ok' => array('#00FF33', "OK"), 'count_warning' => array('#FFFC15', "Warning"), 'count_critical' => array('#FF3727', "Critical"), 'count_unknown' => array('#FF9E00', "Unknown")); 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);