Reduce number of api requests generated by query() method.
This commit is contained in:
@@ -62,9 +62,7 @@ function (angular, _, kbn) {
|
|||||||
// Find items by item names and perform queries
|
// Find items by item names and perform queries
|
||||||
var self = this;
|
var self = this;
|
||||||
return $q.all(_.map(hosts, function (hostname) {
|
return $q.all(_.map(hosts, function (hostname) {
|
||||||
return $q.all(_.map(itemnames, function (name) {
|
return this.findZabbixItem(hostname, itemnames);
|
||||||
return this.findZabbixItem(hostname, name);
|
|
||||||
}, this));
|
|
||||||
}, this)).then(function (items) {
|
}, this)).then(function (items) {
|
||||||
items = _.flatten(items);
|
items = _.flatten(items);
|
||||||
return self.performTimeSeriesQuery(items, from, to)
|
return self.performTimeSeriesQuery(items, from, to)
|
||||||
@@ -309,20 +307,20 @@ function (angular, _, kbn) {
|
|||||||
search: {
|
search: {
|
||||||
name: application
|
name: application
|
||||||
},
|
},
|
||||||
searchWildcardsEnabled: true
|
searchWildcardsEnabled: true,
|
||||||
}
|
}
|
||||||
return this.performZabbixAPIRequest('application.get', params);
|
return this.performZabbixAPIRequest('application.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ZabbixAPIDatasource.prototype.findZabbixItem = function (host, itemname) {
|
ZabbixAPIDatasource.prototype.findZabbixItem = function (host, itemnames) {
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'key_', 'value_type'],
|
output: ['name', 'key_', 'value_type'],
|
||||||
host: host
|
host: host
|
||||||
}
|
}
|
||||||
return this.performZabbixAPIRequest('item.get', params).then(function (items) {
|
return this.performZabbixAPIRequest('item.get', params).then(function (items) {
|
||||||
return _.filter(items, function (item) {
|
return _.filter(items, function (item) {
|
||||||
return expandItemName(item) == itemname;
|
return _.contains(itemnames, expandItemName(item));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -383,7 +381,7 @@ function (angular, _, kbn) {
|
|||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
||||||
// Get hostids from names
|
// Get hostids from names
|
||||||
if (template.host != '*' && template.host) {
|
if (template.host && template.host != '*') {
|
||||||
if (_.isArray(template.host)) {
|
if (_.isArray(template.host)) {
|
||||||
_.each(template.host, function (host) {
|
_.each(template.host, function (host) {
|
||||||
promises.push(this.findZabbixHost(host));
|
promises.push(this.findZabbixHost(host));
|
||||||
@@ -393,7 +391,7 @@ function (angular, _, kbn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get groupids from names
|
// Get groupids from names
|
||||||
else if (template.group != '*' && template.group) {
|
else if (template.group && template.group != '*') {
|
||||||
if (_.isArray(template.group)) {
|
if (_.isArray(template.group)) {
|
||||||
_.each(template.group, function (group) {
|
_.each(template.group, function (group) {
|
||||||
promises.push(this.findZabbixGroup(group));
|
promises.push(this.findZabbixGroup(group));
|
||||||
@@ -403,7 +401,7 @@ function (angular, _, kbn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get applicationids from names
|
// Get applicationids from names
|
||||||
if (template.app != '*' && template.app && !_.isArray(template.app)) {
|
if (template.app && template.app != '*') {
|
||||||
if (_.isArray(template.app)) {
|
if (_.isArray(template.app)) {
|
||||||
_.each(template.app, function (app) {
|
_.each(template.app, function (app) {
|
||||||
promises.push(this.findZabbixApp(app));
|
promises.push(this.findZabbixApp(app));
|
||||||
@@ -487,7 +485,8 @@ function (angular, _, kbn) {
|
|||||||
}), 'hostid');
|
}), 'hostid');
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name']
|
output: ['name'],
|
||||||
|
sortfield: 'name'
|
||||||
}
|
}
|
||||||
if (hostids.length) {
|
if (hostids.length) {
|
||||||
params.hostids = hostids;
|
params.hostids = hostids;
|
||||||
@@ -530,7 +529,8 @@ function (angular, _, kbn) {
|
|||||||
}), 'groupid');
|
}), 'groupid');
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'host']
|
output: ['name', 'host'],
|
||||||
|
sortfield: 'name'
|
||||||
}
|
}
|
||||||
if (groupids.length) {
|
if (groupids.length) {
|
||||||
params.groupids = groupids;
|
params.groupids = groupids;
|
||||||
@@ -569,7 +569,8 @@ function (angular, _, kbn) {
|
|||||||
}), 'groupid');
|
}), 'groupid');
|
||||||
|
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'host']
|
output: ['name', 'host'],
|
||||||
|
sortfield: 'name'
|
||||||
}
|
}
|
||||||
if (groupids.length) {
|
if (groupids.length) {
|
||||||
params.groupids = groupids;
|
params.groupids = groupids;
|
||||||
|
|||||||
Reference in New Issue
Block a user