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); }
public function testGenForecastTarget() { $this->init(); $gpanel = \histou\grafana\graphpanel\GraphPanelFactory::generatePanel('gpanel'); $target = $gpanel->genForecastTarget('host', 'service', 'command', 'perfLabel', '000', '', true); $this->assertSame(null, $target); \histou\template\ForecastTemplate::$config = array('size' => array('method' => 'SimpleLinearRegression', 'forecast' => '20m'), 'time' => array('method' => 'SimpleLinearRegression', 'forecast' => '30m')); $target = $gpanel->genForecastTarget('host', 'service', 'command', 'size'); $expected = array('measurement' => 'metrics', 'alias' => '$col', 'select' => array(array(array('type' => 'field', 'params' => array('value')), array('type' => 'mean', 'params' => array()), array('type' => 'alias', 'params' => array('size-forecast')))), 'tags' => array(array('key' => 'host', 'operator' => '=', 'value' => 'host'), array('condition' => 'AND', 'key' => 'service', 'operator' => '=', 'value' => 'service'), array('condition' => 'AND', 'key' => 'performanceLabel', 'operator' => '=', 'value' => 'size')), 'dsType' => 'influxdb', 'resultFormat' => 'time_series', 'datasource' => 'nagflux_forecast'); $this->assertSame($expected, $target); $this->assertSame(array("20m"), \histou\grafana\dashboard\Dashboard::$forecast); $target = $gpanel->genForecastTarget('host', 'service', 'command', 'time', '000', '', true, true); $expected = array('measurement' => 'metrics', 'alias' => '$col', 'select' => array(array(array('type' => 'field', 'params' => array('value')), array('type' => 'mean', 'params' => array()), array('type' => 'alias', 'params' => array('time-forecast-SimpleLinearRegression')))), 'tags' => array(array('key' => 'host', 'operator' => '=~', 'value' => '/^host$/'), array('condition' => 'AND', 'key' => 'service', 'operator' => '=~', 'value' => '/^service$/'), array('condition' => 'AND', 'key' => 'performanceLabel', 'operator' => '=~', 'value' => '/^time$/')), 'dsType' => 'influxdb', 'resultFormat' => 'time_series', 'datasource' => 'nagflux_forecast'); $this->assertSame($expected, $target); $this->assertSame(array("20m", "30m"), \histou\grafana\dashboard\Dashboard::$forecast); }