Improved query editor - more flexible metric selection.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
*.sublime-workspace
|
*.sublime-workspace
|
||||||
*.sublime-project
|
*.sublime-project
|
||||||
|
|
||||||
|
.idea/
|
||||||
@@ -48,61 +48,51 @@ function (angular, _, kbn) {
|
|||||||
var promises = _.map(options.targets, function(target) {
|
var promises = _.map(options.targets, function(target) {
|
||||||
|
|
||||||
// Remove undefined and hidden targets
|
// Remove undefined and hidden targets
|
||||||
if (target.hide || !target.item) {
|
if (target.hide) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// From !target.item.templated for testing
|
var groupname = target.hostGroup ? templateSrv.replace(target.hostGroup.name) : undefined;
|
||||||
if (false) {
|
var hostname = target.host ? templateSrv.replace(target.host.name) : undefined;
|
||||||
|
var appname = target.application ? templateSrv.replace(target.application.name) : undefined;
|
||||||
|
var itemname = target.item ? templateSrv.replace(target.item.name) : undefined;
|
||||||
|
|
||||||
// Perform request and then handle result
|
// Extract zabbix hosts from hosts string:
|
||||||
var item = [target.item];
|
// "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN]
|
||||||
var alias = [{
|
var hosts = hostname ? splitMetrics(hostname) : undefined;
|
||||||
itemid: target.item.itemid,
|
|
||||||
key_: '',
|
|
||||||
name: target.alias
|
|
||||||
}];
|
|
||||||
return this.performTimeSeriesQuery(item, from, to).then(_.partial(
|
|
||||||
this.handleHistoryResponse, alias));
|
|
||||||
} else {
|
|
||||||
/**
|
|
||||||
* Handle templated target
|
|
||||||
*/
|
|
||||||
|
|
||||||
var itemname = templateSrv.replace(target.item.name);
|
var groups = groupname ? splitMetrics(groupname) : undefined;
|
||||||
var hostname = templateSrv.replace(target.host.name);
|
var apps = appname ? splitMetrics(appname) : undefined;
|
||||||
|
|
||||||
// Extract zabbix hosts from hosts string:
|
// Remove hostnames from item names and then
|
||||||
// "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN]
|
// extract item names
|
||||||
var hosts = splitMetrics(hostname);
|
// "hostname: itemname" --> "itemname"
|
||||||
|
var delete_hostname_pattern = /(?:\[[\w\.]+\]\:\s)/g;
|
||||||
|
var itemnames = itemname ? splitMetrics(itemname.replace(delete_hostname_pattern, '')) : [];
|
||||||
|
//var aliases = itemname.match(itemname_pattern);
|
||||||
|
|
||||||
// Remove hostnames from item names and then
|
// Don't perform query for high number of items
|
||||||
// extract item names
|
// to prevent Grafana slowdown
|
||||||
// "hostname: itemname" --> "itemname"
|
if (itemnames.length < this.limitmetrics) {
|
||||||
var delete_hostname_pattern = /(?:\[[\w\.]+\]\:\s)/g;
|
|
||||||
var itemnames = splitMetrics(itemname.replace(delete_hostname_pattern, ''));
|
|
||||||
//var aliases = itemname.match(itemname_pattern);
|
|
||||||
|
|
||||||
// Don't perform query for high number of items
|
// Find items by item names and perform queries
|
||||||
// to prevent Grafana slowdown
|
var self = this;
|
||||||
if (itemnames && (itemnames.length < this.limitmetrics)) {
|
return this.itemFindQuery(groups, hosts, apps)
|
||||||
|
.then(function (items) {
|
||||||
// Select the host that the item belongs for multiple hosts request
|
if (itemnames.length) {
|
||||||
if (hosts.length > 1) {
|
return _.filter(items, function (item) {
|
||||||
var selectHosts = true;
|
return _.contains(itemnames, expandItemName(item));
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
// Find items by item names and perform queries
|
return items;
|
||||||
var self = this;
|
}
|
||||||
return this.findZabbixItem(hosts, itemnames, selectHosts)
|
}).then(function (items) {
|
||||||
.then(function (items) {
|
items = _.flatten(items);
|
||||||
items = _.flatten(items);
|
return self.performTimeSeriesQuery(items, from, to)
|
||||||
return self.performTimeSeriesQuery(items, from, to)
|
|
||||||
.then(_.partial(self.handleHistoryResponse, items));
|
.then(_.partial(self.handleHistoryResponse, items));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
@@ -394,7 +384,8 @@ function (angular, _, kbn) {
|
|||||||
var hostids = _.map(hosts, 'hostid');
|
var hostids = _.map(hosts, 'hostid');
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'key_', 'value_type'],
|
output: ['name', 'key_', 'value_type'],
|
||||||
hostids: hostids
|
hostids: hostids,
|
||||||
|
searchWildcardsEnabled: true
|
||||||
};
|
};
|
||||||
if (selectHosts) {
|
if (selectHosts) {
|
||||||
params.selectHosts = ['name'];
|
params.selectHosts = ['name'];
|
||||||
@@ -519,15 +510,21 @@ function (angular, _, kbn) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
return $q.all(promises).then(function (results) {
|
return $q.all(promises).then(function (results) {
|
||||||
results = _.flatten(results);
|
results = _.flatten(results);
|
||||||
var groupids = _.map(_.filter(results, function (object) {
|
if (groups) {
|
||||||
return object.groupid;
|
var groupids = _.map(_.filter(results, function (object) {
|
||||||
}), 'groupid');
|
return object.groupid;
|
||||||
var hostids = _.map(_.filter(results, function (object) {
|
}), 'groupid');
|
||||||
return object.hostid;
|
}
|
||||||
}), 'hostid');
|
if (hosts) {
|
||||||
var applicationids = _.map(_.filter(results, function (object) {
|
var hostids = _.map(_.filter(results, function (object) {
|
||||||
return object.applicationid;
|
return object.hostid;
|
||||||
}), 'applicationid');
|
}), 'hostid');
|
||||||
|
}
|
||||||
|
if (apps) {
|
||||||
|
var applicationids = _.map(_.filter(results, function (object) {
|
||||||
|
return object.applicationid;
|
||||||
|
}), 'applicationid');
|
||||||
|
}
|
||||||
|
|
||||||
return self.performItemSuggestQuery(hostids, applicationids, groupids);
|
return self.performItemSuggestQuery(hostids, applicationids, groupids);
|
||||||
});
|
});
|
||||||
@@ -549,12 +546,16 @@ function (angular, _, kbn) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
return $q.all(promises).then(function (results) {
|
return $q.all(promises).then(function (results) {
|
||||||
results = _.flatten(results);
|
results = _.flatten(results);
|
||||||
var groupids = _.map(_.filter(results, function (object) {
|
if (groups) {
|
||||||
return object.groupid;
|
var groupids = _.map(_.filter(results, function (object) {
|
||||||
}), 'groupid');
|
return object.groupid;
|
||||||
var hostids = _.map(_.filter(results, function (object) {
|
}), 'groupid');
|
||||||
return object.hostid;
|
}
|
||||||
}), 'hostid');
|
if (hosts) {
|
||||||
|
var hostids = _.map(_.filter(results, function (object) {
|
||||||
|
return object.hostid;
|
||||||
|
}), 'hostid');
|
||||||
|
}
|
||||||
|
|
||||||
return self.performAppSuggestQuery(hostids, groupids);
|
return self.performAppSuggestQuery(hostids, groupids);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ function (angular, _) {
|
|||||||
$scope.selectHostGroup = function() {
|
$scope.selectHostGroup = function() {
|
||||||
$scope.updateHostList()
|
$scope.updateHostList()
|
||||||
$scope.updateAppList();
|
$scope.updateAppList();
|
||||||
|
$scope.updateItemList();
|
||||||
|
|
||||||
$scope.target.errors = validateTarget($scope.target);
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
||||||
@@ -70,8 +71,8 @@ function (angular, _) {
|
|||||||
* Call when host selected
|
* Call when host selected
|
||||||
*/
|
*/
|
||||||
$scope.selectHost = function() {
|
$scope.selectHost = function() {
|
||||||
$scope.updateItemList();
|
|
||||||
$scope.updateAppList();
|
$scope.updateAppList();
|
||||||
|
$scope.updateItemList();
|
||||||
|
|
||||||
$scope.target.errors = validateTarget($scope.target);
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
||||||
@@ -150,7 +151,7 @@ function (angular, _) {
|
|||||||
$scope.metric.hostList = [];
|
$scope.metric.hostList = [];
|
||||||
addTemplatedVariables($scope.metric.hostList);
|
addTemplatedVariables($scope.metric.hostList);
|
||||||
|
|
||||||
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : [];
|
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : undefined;
|
||||||
$scope.datasource.hostFindQuery(groups).then(function (hosts) {
|
$scope.datasource.hostFindQuery(groups).then(function (hosts) {
|
||||||
$scope.metric.hostList = $scope.metric.hostList.concat(hosts);
|
$scope.metric.hostList = $scope.metric.hostList.concat(hosts);
|
||||||
|
|
||||||
@@ -171,8 +172,8 @@ function (angular, _) {
|
|||||||
$scope.metric.applicationList = [];
|
$scope.metric.applicationList = [];
|
||||||
addTemplatedVariables($scope.metric.applicationList);
|
addTemplatedVariables($scope.metric.applicationList);
|
||||||
|
|
||||||
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : [];
|
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : undefined;
|
||||||
var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : [];
|
var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
|
||||||
$scope.datasource.appFindQuery(hosts, groups).then(function (apps) {
|
$scope.datasource.appFindQuery(hosts, groups).then(function (apps) {
|
||||||
// TODO: work with app names, not objects
|
// TODO: work with app names, not objects
|
||||||
var apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
|
var apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
|
||||||
@@ -197,9 +198,9 @@ function (angular, _) {
|
|||||||
$scope.metric.itemList = [];
|
$scope.metric.itemList = [];
|
||||||
addTemplatedVariables($scope.metric.itemList);
|
addTemplatedVariables($scope.metric.itemList);
|
||||||
|
|
||||||
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : [];
|
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : undefined;
|
||||||
var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : [];
|
var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
|
||||||
var apps = $scope.target.application ? splitMetrics(templateSrv.replace($scope.target.application.name)) : [];
|
var apps = $scope.target.application ? splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
|
||||||
$scope.datasource.itemFindQuery(groups, hosts, apps).then(function (items) {
|
$scope.datasource.itemFindQuery(groups, hosts, apps).then(function (items) {
|
||||||
// Show only unique item names
|
// Show only unique item names
|
||||||
var uniq_items = _.uniq(items, function (item) {
|
var uniq_items = _.uniq(items, function (item) {
|
||||||
|
|||||||
Reference in New Issue
Block a user