Fixed #191 - display host name for multiple metrics.

This commit is contained in:
Alexander Zobnin
2016-04-11 23:12:38 +03:00
parent eb9722aef0
commit 49ea07451f
3 changed files with 15 additions and 10 deletions

View File

@@ -151,13 +151,13 @@ export class ZabbixAPIDatasource {
var valueType = trendValueFunc ? trendValueFunc.params[0] : "avg"; var valueType = trendValueFunc ? trendValueFunc.params[0] : "avg";
getHistory = self.zabbixAPI.getTrend(items, from, to).then(function(history) { getHistory = self.zabbixAPI.getTrend(items, from, to).then(function(history) {
return self.queryProcessor.handleTrends(history, addHostName, valueType); return self.queryProcessor.handleTrends(history, items, addHostName, valueType);
}); });
} else { } else {
// Use history // Use history
getHistory = self.zabbixCache.getHistory(items, from, to).then(function(history) { getHistory = self.zabbixCache.getHistory(items, from, to).then(function(history) {
return self.queryProcessor.handleHistory(history, addHostName); return self.queryProcessor.handleHistory(history, items, addHostName);
}); });
} }

View File

@@ -217,7 +217,7 @@ angular.module('grafana.services').factory('QueryProcessor', function($q) {
* datapoints: [[<value>, <unixtime>], ...] * datapoints: [[<value>, <unixtime>], ...]
* } * }
*/ */
convertHistory(history, addHostName, convertPointCallback) { convertHistory(history, items, addHostName, convertPointCallback) {
/** /**
* Response should be in the format: * Response should be in the format:
* data: [ * data: [
@@ -231,12 +231,13 @@ angular.module('grafana.services').factory('QueryProcessor', function($q) {
// Group history by itemid // Group history by itemid
var grouped_history = _.groupBy(history, 'itemid'); var grouped_history = _.groupBy(history, 'itemid');
var hosts = _.indexBy(_.flatten(_.map(items, 'hosts')), 'hostid');
return _.map(grouped_history, function(hist, itemid) { return _.map(grouped_history, function(hist, itemid) {
var item = self.cache.getItem(itemid); var item = self.cache.getItem(itemid);
var alias = item.name; var alias = item.name;
if (addHostName) { if (_.keys(hosts).length > 1 || addHostName) {
var host = self.cache.getHost(item.hostid); var host = hosts[item.hostid];
alias = host.name + ": " + alias; alias = host.name + ": " + alias;
} }
return { return {
@@ -246,13 +247,13 @@ angular.module('grafana.services').factory('QueryProcessor', function($q) {
}); });
} }
handleHistory(history, addHostName) { handleHistory(history, items, addHostName) {
return this.convertHistory(history, addHostName, convertHistoryPoint); return this.convertHistory(history, items, addHostName, convertHistoryPoint);
} }
handleTrends(history, addHostName, valueType) { handleTrends(history, items, addHostName, valueType) {
var convertPointCallback = _.partial(convertTrendPoint, valueType); var convertPointCallback = _.partial(convertTrendPoint, valueType);
return this.convertHistory(history, addHostName, convertPointCallback); return this.convertHistory(history, items, addHostName, convertPointCallback);
} }
handleSLAResponse(itservice, slaProperty, slaObject) { handleSLAResponse(itservice, slaProperty, slaObject) {

View File

@@ -155,7 +155,11 @@ function ZabbixAPIService($q, alertSrv, zabbixAPICoreService) {
'state' 'state'
], ],
sortfield: 'name', sortfield: 'name',
webitems: true webitems: true,
selectHosts: [
'hostid',
'name'
]
}; };
if (hostids) { if (hostids) {
params.hostids = hostids; params.hostids = hostids;