From 49b18e17d7574540cdbf8d208c968ea4db202954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 6 Jan 2015 09:10:20 +0100 Subject: [PATCH] added test query feature to grafana datasource to generate a test graph on first login --- src/app/features/all.js | 1 + .../grafanaDatasource/datasource.js} | 14 +++++++++++++- .../partials/query.editor.html | 17 +++++++++++++++++ src/app/services/all.js | 1 - src/app/services/backendSrv.js | 9 +++++---- 5 files changed, 36 insertions(+), 6 deletions(-) rename src/app/{services/grafanaDatasource.js => features/grafanaDatasource/datasource.js} (76%) create mode 100644 src/app/features/grafanaDatasource/partials/query.editor.html diff --git a/src/app/features/all.js b/src/app/features/all.js index 5adb048d879..2a22f0c5dd3 100644 --- a/src/app/features/all.js +++ b/src/app/features/all.js @@ -9,4 +9,5 @@ define([ './dashboard/all', './admin/accountCtrl', './admin/datasourcesCtrl', + './grafanaDatasource/datasource', ], function () {}); diff --git a/src/app/services/grafanaDatasource.js b/src/app/features/grafanaDatasource/datasource.js similarity index 76% rename from src/app/services/grafanaDatasource.js rename to src/app/features/grafanaDatasource/datasource.js index d20a221b416..6f168545b80 100644 --- a/src/app/services/grafanaDatasource.js +++ b/src/app/features/grafanaDatasource/datasource.js @@ -1,8 +1,9 @@ define([ 'angular', 'lodash', + 'kbn', ], -function (angular, _) { +function (angular, _, kbn) { 'use strict'; var module = angular.module('grafana.services'); @@ -12,6 +13,9 @@ function (angular, _) { function GrafanaDatasource() { this.type = 'grafana'; this.grafanaDB = true; + this.name = "grafana"; + this.supportMetrics = true; + this.editorSrc = 'app/features/grafanaDatasource/partials/query.editor.html'; } GrafanaDatasource.prototype.getDashboard = function(id, isTemp) { @@ -31,6 +35,14 @@ function (angular, _) { }); }; + GrafanaDatasource.prototype.query = function(options) { + // get from & to in seconds + var from = kbn.parseDate(options.range.from).getTime(); + var to = kbn.parseDate(options.range.to).getTime(); + + return backendSrv.get('/api/metrics/test', { from: from, to: to, maxDataPoints: options.maxDataPoints }); + }; + GrafanaDatasource.prototype.saveDashboard = function(dashboard) { // remove id if title has changed if (dashboard.title !== dashboard.originalTitle) { diff --git a/src/app/features/grafanaDatasource/partials/query.editor.html b/src/app/features/grafanaDatasource/partials/query.editor.html new file mode 100644 index 00000000000..032fa49e602 --- /dev/null +++ b/src/app/features/grafanaDatasource/partials/query.editor.html @@ -0,0 +1,17 @@ + +
+
+
+
Test graph
+ +

+ This is just a test data source that generates random walk series. If this is your only data source + open the left side menu and goto data sources admin screen and add your data sources. You can change + data source using the button to the left of the Add query button. +

+
+
+ +
+
+ diff --git a/src/app/services/all.js b/src/app/services/all.js index 91ae276691b..c4067274dd2 100644 --- a/src/app/services/all.js +++ b/src/app/services/all.js @@ -6,6 +6,5 @@ define([ './keyboardManager', './popoverSrv', './backendSrv', - './grafanaDatasource', ], function () {}); diff --git a/src/app/services/backendSrv.js b/src/app/services/backendSrv.js index 6f5859c8a29..843f24a0703 100644 --- a/src/app/services/backendSrv.js +++ b/src/app/services/backendSrv.js @@ -10,8 +10,8 @@ function (angular, _, config) { module.service('backendSrv', function($http, alertSrv) { - this.get = function(url) { - return this.request({ method: 'GET', url: url }); + this.get = function(url, params) { + return this.request({ method: 'GET', url: url, params: params }); }; this.delete = function(url) { @@ -30,7 +30,8 @@ function (angular, _, config) { var httpOptions = { url: config.appSubUrl + options.url, method: options.method, - data: options.data + data: options.data, + params: options.params, }; return $http(httpOptions).then(function(results) { @@ -54,7 +55,7 @@ function (angular, _, config) { } if (data.message) { - alertSrv.set("Error", data.message, data.severity, 10000); + alertSrv.set("Problem!", data.message, data.severity, 10000); } throw data;