Add splitMetrics() function for extracting metrics from "{metric1,metcic2,...,metricN}" string.

This commit is contained in:
Alexander Zobnin
2015-06-03 23:50:10 +03:00
parent 3a31b8b27c
commit f84443692b

View File

@@ -73,18 +73,13 @@ function (angular, _, kbn) {
// Extract zabbix hosts from hosts string: // Extract zabbix hosts from hosts string:
// "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN] // "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN]
var host_pattern = /([^{},]+)/g; var hosts = splitMetrics(hostname);
var hosts = hostname.match(host_pattern);
// 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 remove_brackets_pattern = /^{|}$/g; var itemnames = splitMetrics(itemname.replace(delete_hostname_pattern, ''));
var itemname_split_pattern = /(,(?!\s))/g;
var itemnames = itemname.replace(delete_hostname_pattern, '')
.replace(remove_brackets_pattern, '')
.split(itemname_split_pattern);
//var aliases = itemname.match(itemname_pattern); //var aliases = itemname.match(itemname_pattern);
// Don't perform query for high number of items // Don't perform query for high number of items
@@ -433,22 +428,13 @@ function (angular, _, kbn) {
if (part[0] === '{') { if (part[0] === '{') {
// Convert multiple mettrics to array // Convert multiple mettrics to array
// "{metric1,metcic2,...,metricN}" --> [metric1, metcic2,..., metricN] // "{metric1,metcic2,...,metricN}" --> [metric1, metcic2,..., metricN]
parts.push(part.slice(1, -1).split(',')); parts.push(splitMetrics(part));
} else { } else {
parts.push(part); parts.push(part);
} }
}); });
var template = _.object(['group', 'host', 'app', 'key'], parts) var template = _.object(['group', 'host', 'app', 'key'], parts)
var params = {
output: ['name'],
sortfield: 'name',
// Case insensitive search
search: {
name : template.group
}
};
// Get items // Get items
if (parts.length === 4) { if (parts.length === 4) {
return this.itemFindQuery(template); return this.itemFindQuery(template);
@@ -635,6 +621,20 @@ function (angular, _, kbn) {
}); });
/**
* Convert multiple mettrics to array
* "{metric1,metcic2,...,metricN}" --> [metric1, metcic2,..., metricN]
*
* @param {string} metrics "{metric1,metcic2,...,metricN}"
* @return {Array} [metric1, metcic2,..., metricN]
*/
function splitMetrics(metrics) {
var remove_brackets_pattern = /^{|}$/g;
var metric_split_pattern = /(,(?!\s))/g;
return metrics.replace(remove_brackets_pattern, '').split(metric_split_pattern)
}
/** /**
* Expand item parameters, for example: * Expand item parameters, for example:
* CPU $2 time ($3) --> CPU system time (avg1) * CPU $2 time ($3) --> CPU system time (avg1)