Exemple #1
0
 /**
     Creates a new Markdown row.
     @param string $message contains the body.
     @param string $header  could contain the headline.
     @return object
     **/
 public static function genRow($message, $mode = \histou\grafana\TextPanel::TEXT, $header = '')
 {
     $panel = new \histou\grafana\TextPanel('');
     $panel->setMode($mode);
     $panel->setContent($message);
     $row = new \histou\grafana\Row($header);
     $row->addPanel($panel);
     return $row;
 }
Exemple #2
0
 public function testErrorMarkdownDashboard()
 {
     $this->init();
     $panel = new \histou\grafana\TextPanel('', 1);
     $panel->setMode(\histou\grafana\TextPanel::MARKDOWN);
     $panel->setContent("foo");
     $row = new \histou\grafana\Row("ERROR");
     $row->addPanel($panel);
     $dashboard = new \histou\grafana\dashboard\dashboardInfluxdb('Error');
     $dashboard->addRow($row);
     $this->assertEquals($dashboard, \histou\Debug::errorMarkdownDashboard("foo"));
 }
Exemple #3
0
 public function testCreatePanel()
 {
     $row = new \histou\grafana\Row('r1', '100px');
     $this->assertSame('r1', $row->toArray()['title']);
     $row->setEditable(false);
     $this->assertSame(false, $row->toArray()['editable']);
     $row->setCustomProperty('foo', 'bar');
     $this->assertSame('bar', $row->toArray()['foo']);
 }
 $colors = array('#085DFF', '#07ff78', "#BA43A9", "#C15C17");
 $dashboard = \histou\grafana\dashboard\DashboardFactory::generateDashboard($perfData['host'] . '-' . $perfData['service']);
 $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;
Exemple #5
0
 $suitePanel->addTarget($suitePanel->genTargetSimple($perfData['host'], $perfData['service'], $perfData['command'], 'suite__critical', '#FF3727', 'critical'));
 $suiteRow->addPanel($suitePanel);
 //Suite Stat Panel
 $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'), '', '');
Exemple #6
0
/**
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);