mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Time is now sent in utc when time correction is set to utc #143
This commit is contained in:
parent
a54f05e287
commit
ef69d692ef
@ -7,5 +7,6 @@ define([
|
|||||||
'./datasourceSrv',
|
'./datasourceSrv',
|
||||||
'./keyboardManager',
|
'./keyboardManager',
|
||||||
'./annotationsSrv',
|
'./annotationsSrv',
|
||||||
|
'./graphite/graphiteDatasource',
|
||||||
],
|
],
|
||||||
function () {});
|
function () {});
|
@ -1,15 +1,15 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'underscore',
|
'underscore',
|
||||||
'config',
|
'config'
|
||||||
'./graphite/graphiteDatasource'
|
|
||||||
],
|
],
|
||||||
function (angular, _, config, GraphiteDatasource) {
|
function (angular, _, config) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('kibana.services');
|
var module = angular.module('kibana.services');
|
||||||
|
|
||||||
module.service('datasourceSrv', function($q, filterSrv, $http) {
|
module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource) {
|
||||||
|
|
||||||
var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } );
|
var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } );
|
||||||
|
|
||||||
this.default = new GraphiteDatasource(defaultDatasource, $q, filterSrv, $http);
|
this.default = new GraphiteDatasource(defaultDatasource, $q, filterSrv, $http);
|
||||||
|
@ -9,158 +9,168 @@ define([
|
|||||||
function (angular, _, $, config, kbn, moment) {
|
function (angular, _, $, config, kbn, moment) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function GraphiteDatasource(datasource, $q, filterSrv, $http) {
|
var module = angular.module('kibana.services');
|
||||||
this.url = datasource.url;
|
|
||||||
this.type = 'graphite';
|
|
||||||
this.basicAuth = datasource.basicAuth;
|
|
||||||
this.$q = $q;
|
|
||||||
this.filterSrv = filterSrv;
|
|
||||||
this.$http = $http;
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.query = function(options) {
|
module.factory('GraphiteDatasource', function(dashboard, $q, filterSrv, $http) {
|
||||||
try {
|
|
||||||
var graphOptions = {
|
|
||||||
from: this.translateTime(options.range.from),
|
|
||||||
until: this.translateTime(options.range.to),
|
|
||||||
targets: options.targets,
|
|
||||||
format: options.format,
|
|
||||||
maxDataPoints: options.maxDataPoints,
|
|
||||||
};
|
|
||||||
|
|
||||||
var params = this.buildGraphiteParams(graphOptions);
|
function GraphiteDatasource(datasource, $q, filterSrv, $http) {
|
||||||
|
this.url = datasource.url;
|
||||||
|
this.type = 'graphite';
|
||||||
|
this.basicAuth = datasource.basicAuth;
|
||||||
|
this.$q = $q;
|
||||||
|
this.filterSrv = filterSrv;
|
||||||
|
this.$http = $http;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.format === 'png') {
|
GraphiteDatasource.prototype.query = function(options) {
|
||||||
return this.$q.when(this.url + '/render' + '?' + params.join('&'));
|
try {
|
||||||
}
|
var graphOptions = {
|
||||||
|
from: this.translateTime(options.range.from),
|
||||||
|
until: this.translateTime(options.range.to),
|
||||||
|
targets: options.targets,
|
||||||
|
format: options.format,
|
||||||
|
maxDataPoints: options.maxDataPoints,
|
||||||
|
};
|
||||||
|
|
||||||
return this.doGraphiteRequest({
|
var params = this.buildGraphiteParams(graphOptions);
|
||||||
method: 'POST',
|
|
||||||
url: '/render',
|
if (options.format === 'png') {
|
||||||
data: params.join('&'),
|
return this.$q.when(this.url + '/render' + '?' + params.join('&'));
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
return this.$q.reject(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.events = function(options) {
|
return this.doGraphiteRequest({
|
||||||
try {
|
method: 'POST',
|
||||||
var tags = '';
|
url: '/render',
|
||||||
if (options.tags) {
|
data: params.join('&'),
|
||||||
tags = '&tags=' + options.tags;
|
headers: {
|
||||||
}
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
|
||||||
return this.doGraphiteRequest({
|
|
||||||
method: 'GET',
|
|
||||||
url: '/events/get_data?from=' + this.translateTime(options.range.from) + '&until=' + this.translateTime(options.range.to) + tags,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
return this.$q.reject(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.translateTime = function(date) {
|
|
||||||
if (_.isString(date)) {
|
|
||||||
if (date === 'now') {
|
|
||||||
return 'now';
|
|
||||||
}
|
|
||||||
else if (date.indexOf('now') >= 0) {
|
|
||||||
date = date.substring(3);
|
|
||||||
date = date.replace('m', 'min');
|
|
||||||
date = date.replace('M', 'mon');
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
date = kbn.parseDate(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
date = moment.utc(date).local();
|
|
||||||
|
|
||||||
if (config.timezoneOffset) {
|
|
||||||
date = date.zone(config.timezoneOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
return date.format('HH:mm_YYYYMMDD');
|
|
||||||
};
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.metricFindQuery = function(query) {
|
|
||||||
var interpolated;
|
|
||||||
try {
|
|
||||||
interpolated = this.filterSrv.applyFilterToTarget(query);
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
return this.$q.reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.doGraphiteRequest({method: 'GET', url: '/metrics/find/?query=' + interpolated })
|
|
||||||
.then(function(results) {
|
|
||||||
return _.map(results.data, function(metric) {
|
|
||||||
return {
|
|
||||||
text: metric.text,
|
|
||||||
expandable: metric.expandable ? true : false
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.listDashboards = function(query) {
|
|
||||||
return this.doGraphiteRequest({ method: 'GET', url: '/dashboard/find/', params: {query: query || ''} })
|
|
||||||
.then(function(results) {
|
|
||||||
return results.data.dashboards;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.loadDashboard = function(dashName) {
|
|
||||||
return this.doGraphiteRequest({method: 'GET', url: '/dashboard/load/' + encodeURIComponent(dashName) });
|
|
||||||
};
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.doGraphiteRequest = function(options) {
|
|
||||||
if (this.basicAuth) {
|
|
||||||
options.withCredentials = true;
|
|
||||||
options.headers = options.headers || {};
|
|
||||||
options.headers.Authorization = 'Basic ' + config.graphiteBasicAuth;
|
|
||||||
}
|
|
||||||
|
|
||||||
options.url = this.url + options.url;
|
|
||||||
|
|
||||||
return this.$http(options);
|
|
||||||
};
|
|
||||||
|
|
||||||
GraphiteDatasource.prototype.buildGraphiteParams = function(options) {
|
|
||||||
var clean_options = [];
|
|
||||||
var graphite_options = ['target', 'targets', 'from', 'until', 'rawData', 'format', 'maxDataPoints'];
|
|
||||||
|
|
||||||
if (options.format !== 'png') {
|
|
||||||
options['format'] = 'json';
|
|
||||||
}
|
|
||||||
|
|
||||||
_.each(options, function (value, key) {
|
|
||||||
if ($.inArray(key, graphite_options) === -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key === "targets") {
|
|
||||||
_.each(value, function (value) {
|
|
||||||
if (!value.hide) {
|
|
||||||
var targetValue = this.filterSrv.applyFilterToTarget(value.target);
|
|
||||||
clean_options.push("target=" + encodeURIComponent(targetValue));
|
|
||||||
}
|
}
|
||||||
}, this);
|
});
|
||||||
}
|
}
|
||||||
else if (value !== null) {
|
catch(err) {
|
||||||
clean_options.push(key + "=" + encodeURIComponent(value));
|
return this.$q.reject(err);
|
||||||
}
|
}
|
||||||
}, this);
|
};
|
||||||
return clean_options;
|
|
||||||
};
|
GraphiteDatasource.prototype.events = function(options) {
|
||||||
|
try {
|
||||||
|
var tags = '';
|
||||||
|
if (options.tags) {
|
||||||
|
tags = '&tags=' + options.tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.doGraphiteRequest({
|
||||||
|
method: 'GET',
|
||||||
|
url: '/events/get_data?from=' + this.translateTime(options.range.from) + '&until=' + this.translateTime(options.range.to) + tags,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
return this.$q.reject(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphiteDatasource.prototype.translateTime = function(date) {
|
||||||
|
if (_.isString(date)) {
|
||||||
|
if (date === 'now') {
|
||||||
|
return 'now';
|
||||||
|
}
|
||||||
|
else if (date.indexOf('now') >= 0) {
|
||||||
|
date = date.substring(3);
|
||||||
|
date = date.replace('m', 'min');
|
||||||
|
date = date.replace('M', 'mon');
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
date = kbn.parseDate(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
date = moment.utc(date);
|
||||||
|
|
||||||
|
if (dashboard.current.timezone === 'browser') {
|
||||||
|
date = date.local();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.timezoneOffset) {
|
||||||
|
date = date.zone(config.timezoneOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
return date.format('HH:mm_YYYYMMDD');
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphiteDatasource.prototype.metricFindQuery = function(query) {
|
||||||
|
var interpolated;
|
||||||
|
try {
|
||||||
|
interpolated = this.filterSrv.applyFilterToTarget(query);
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
return this.$q.reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.doGraphiteRequest({method: 'GET', url: '/metrics/find/?query=' + interpolated })
|
||||||
|
.then(function(results) {
|
||||||
|
return _.map(results.data, function(metric) {
|
||||||
|
return {
|
||||||
|
text: metric.text,
|
||||||
|
expandable: metric.expandable ? true : false
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphiteDatasource.prototype.listDashboards = function(query) {
|
||||||
|
return this.doGraphiteRequest({ method: 'GET', url: '/dashboard/find/', params: {query: query || ''} })
|
||||||
|
.then(function(results) {
|
||||||
|
return results.data.dashboards;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphiteDatasource.prototype.loadDashboard = function(dashName) {
|
||||||
|
return this.doGraphiteRequest({method: 'GET', url: '/dashboard/load/' + encodeURIComponent(dashName) });
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphiteDatasource.prototype.doGraphiteRequest = function(options) {
|
||||||
|
if (this.basicAuth) {
|
||||||
|
options.withCredentials = true;
|
||||||
|
options.headers = options.headers || {};
|
||||||
|
options.headers.Authorization = 'Basic ' + config.graphiteBasicAuth;
|
||||||
|
}
|
||||||
|
|
||||||
|
options.url = this.url + options.url;
|
||||||
|
|
||||||
|
return this.$http(options);
|
||||||
|
};
|
||||||
|
|
||||||
|
GraphiteDatasource.prototype.buildGraphiteParams = function(options) {
|
||||||
|
var clean_options = [];
|
||||||
|
var graphite_options = ['target', 'targets', 'from', 'until', 'rawData', 'format', 'maxDataPoints'];
|
||||||
|
|
||||||
|
if (options.format !== 'png') {
|
||||||
|
options['format'] = 'json';
|
||||||
|
}
|
||||||
|
|
||||||
|
_.each(options, function (value, key) {
|
||||||
|
if ($.inArray(key, graphite_options) === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key === "targets") {
|
||||||
|
_.each(value, function (value) {
|
||||||
|
if (!value.hide) {
|
||||||
|
var targetValue = this.filterSrv.applyFilterToTarget(value.target);
|
||||||
|
clean_options.push("target=" + encodeURIComponent(targetValue));
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
else if (value !== null) {
|
||||||
|
clean_options.push(key + "=" + encodeURIComponent(value));
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
return clean_options;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return GraphiteDatasource;
|
return GraphiteDatasource;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
2
src/css/bootstrap.dark.min.css
vendored
2
src/css/bootstrap.dark.min.css
vendored
File diff suppressed because one or more lines are too long
2
src/css/bootstrap.light.min.css
vendored
2
src/css/bootstrap.light.min.css
vendored
File diff suppressed because one or more lines are too long
@ -156,13 +156,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.histogram-legend-dot {
|
|
||||||
display:inline-block;
|
|
||||||
height:10px;
|
|
||||||
width:10px;
|
|
||||||
border-radius:5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.histogram-legend-item {
|
.histogram-legend-item {
|
||||||
display:inline-block;
|
display:inline-block;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user