示例#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;
 }
示例#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"));
 }
    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);
            $panel->addTarget($panel->genDowntimeTarget($perfData['host'], $perfData['service'], $perfData['command'], $perfLabel));
            $target = $panel->addWarnToTarget($target, $perfLabel, false);
            $target = $panel->addCritToTarget($target, $perfLabel, false);
            $panel->addTarget($target);
            $panel->addRegexColor("/^db_.*?_{$label}-value\$/", $colors[$currentColorIndex++]);
        }
        $panel->addRegexColor('/^db_.*?-warn-?(min|max)?$/', '#FFFC15');
        $panel->addRegexColor('/^db_.*?-crit-?(min|max)?$/', '#FF3727');
        $row->addPanel($panel);
    }
    $row->setCustomProperty("repeat", $templateName);
    $dashboard->addRow($row);
    return $dashboard;
};
示例#4
0
    $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;
};