query() method refactoring.
This commit is contained in:
@@ -47,53 +47,55 @@ function (angular, _, kbn) {
|
|||||||
// Create request for each target
|
// Create request for each target
|
||||||
var promises = _.map(options.targets, function(target) {
|
var promises = _.map(options.targets, function(target) {
|
||||||
|
|
||||||
// Remove undefined and hidden targets
|
// Don't show undefined and hidden targets
|
||||||
if (target.hide || !target.group || !target.host || !target.application || !target.item) {
|
if (target.hide || !target.group || !target.host
|
||||||
|
|| !target.application || !target.item) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupname = target.group ? templateSrv.replace(target.group.name) : undefined;
|
// Replace templated variables
|
||||||
var hostname = target.host ? templateSrv.replace(target.host.name) : undefined;
|
var groupname = templateSrv.replace(target.group.name);
|
||||||
var appname = target.application ? templateSrv.replace(target.application.name) : undefined;
|
var hostname = templateSrv.replace(target.host.name);
|
||||||
var itemname = target.item ? templateSrv.replace(target.item.name) : undefined;
|
var appname = templateSrv.replace(target.application.name);
|
||||||
|
var itemname = templateSrv.replace(target.item.name);
|
||||||
|
|
||||||
// Extract zabbix hosts from hosts string:
|
// Extract zabbix groups, hosts and apps from string:
|
||||||
// "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN]
|
// "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN]
|
||||||
var hosts = hostname ? splitMetrics(hostname) : undefined;
|
var groups = splitMetrics(groupname);
|
||||||
|
var hosts = splitMetrics(hostname);
|
||||||
var groups = groupname ? splitMetrics(groupname) : undefined;
|
var apps = splitMetrics(appname);
|
||||||
var apps = appname ? splitMetrics(appname) : undefined;
|
|
||||||
|
|
||||||
// Remove hostnames from item names and then
|
// Remove hostnames from item names and then
|
||||||
// extract item names
|
// extract item names
|
||||||
// "hostname: itemname" --> "itemname"
|
// "hostname: itemname" --> "itemname"
|
||||||
var delete_hostname_pattern = /(?:\[[\w\.]+\]\:\s)/g;
|
var delete_hostname_pattern = /(?:\[[\w\.]+\]\:\s)/g;
|
||||||
var itemnames = itemname ? splitMetrics(itemname.replace(delete_hostname_pattern, '')) : [];
|
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.length < this.limitmetrics) {
|
return this.itemFindQuery(groups, hosts, apps)
|
||||||
|
.then(function (items) {
|
||||||
|
if (itemnames == 'All') {
|
||||||
|
return items;
|
||||||
|
} else {
|
||||||
|
|
||||||
// Find items by item names and perform queries
|
// Filtering items
|
||||||
var self = this;
|
return _.filter(items, function (item) {
|
||||||
return this.itemFindQuery(groups, hosts, apps)
|
return _.contains(itemnames, expandItemName(item));
|
||||||
.then(function (items) {
|
});
|
||||||
if (itemnames != 'All') {
|
}
|
||||||
return _.filter(items, function (item) {
|
}).then(function (items) {
|
||||||
return _.contains(itemnames, expandItemName(item));
|
|
||||||
});
|
// Don't perform query for high number of items
|
||||||
} else {
|
// to prevent Grafana slowdown
|
||||||
return items;
|
if (items.length > self.limitmetrics) {
|
||||||
}
|
return [];
|
||||||
}).then(function (items) {
|
} else {
|
||||||
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 {
|
});
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
return $q.all(_.flatten(promises)).then(function (results) {
|
return $q.all(_.flatten(promises)).then(function (results) {
|
||||||
|
|||||||
Reference in New Issue
Block a user