mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Co-authored-by: Christian González <cgonzalez@opennebula.io>
This commit is contained in:
parent
37b5e28cf8
commit
c1dcf0e42a
@ -127,6 +127,19 @@ module OpenNebula
|
||||
return hash
|
||||
end
|
||||
|
||||
def monitoring_last(xml_method, *args)
|
||||
rc = @client.call(xml_method, *args)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
xmldoc = XMLElement.new
|
||||
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
||||
|
||||
xmldoc.to_hash
|
||||
end
|
||||
|
||||
private
|
||||
# Calls to the corresponding info method to retreive the pool
|
||||
# representation in XML format
|
||||
|
@ -202,6 +202,10 @@ module OpenNebula
|
||||
return super(VM_POOL_METHODS[:monitoring], xpaths, filter_flag)
|
||||
end
|
||||
|
||||
def monitoring_last(filter_flag=INFO_ALL)
|
||||
return super(VM_POOL_METHODS[:monitoring], filter_flag, 0)
|
||||
end
|
||||
|
||||
# Retrieves the monitoring data for all the VMs in the pool, in XML
|
||||
#
|
||||
# @param [Integer] filter_flag Optional filter flag to retrieve all or
|
||||
|
@ -309,7 +309,7 @@ class SunstoneServer < CloudServer
|
||||
########################################################################
|
||||
# Accounting & Monitoring
|
||||
########################################################################
|
||||
def get_pool_monitoring(resource, meters)
|
||||
def get_pool_monitoring(resource)
|
||||
#pool_element
|
||||
pool = case resource
|
||||
when "vm", "VM"
|
||||
@ -321,9 +321,7 @@ class SunstoneServer < CloudServer
|
||||
return [200, error.to_json]
|
||||
end
|
||||
|
||||
meters_a = meters.split(',')
|
||||
|
||||
rc = pool.monitoring(meters_a)
|
||||
rc = pool.monitoring_last
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
error = Error.new(rc.message)
|
||||
|
@ -164,7 +164,7 @@ define(function(require) {
|
||||
});
|
||||
}
|
||||
},
|
||||
"list": function(params, resource, path, process) {
|
||||
"list": function(params, resource, path, process, extra_params = {}, async = true) {
|
||||
var callback = params.success;
|
||||
var callbackError = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
@ -182,14 +182,12 @@ define(function(require) {
|
||||
_clearCache(cache_name);
|
||||
}
|
||||
|
||||
if (!force &&
|
||||
listCache[cache_name] &&
|
||||
listCache[cache_name]["timestamp"] + CACHE_EXPIRE > new Date().getTime()) {
|
||||
|
||||
//console.log(cache_name+" list. Cache used");
|
||||
|
||||
return callback ?
|
||||
callback(request, listCache[cache_name]["data"]) : null;
|
||||
if (
|
||||
!force &&
|
||||
listCache[cache_name] &&
|
||||
listCache[cache_name]["timestamp"] + CACHE_EXPIRE > new Date().getTime()
|
||||
) {
|
||||
return callback ? callback(request, listCache[cache_name]["data"]) : null;
|
||||
}
|
||||
|
||||
// TODO: Because callbacks are queued, we may need to force a
|
||||
@ -204,19 +202,20 @@ define(function(require) {
|
||||
error : callbackError
|
||||
});
|
||||
|
||||
//console.log(cache_name+" list. Callback queued");
|
||||
|
||||
if (listWaiting[cache_name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
listWaiting[cache_name] = true;
|
||||
var pool_filter = Config.isChangedFilter()?-4:-2;
|
||||
//console.log(cache_name+" list. NO cache, calling ajax");
|
||||
|
||||
let data = $.extend(extra_params, { timeout: timeout, pool_filter: pool_filter })
|
||||
|
||||
$.ajax({
|
||||
url: reqPath,
|
||||
type: "GET",
|
||||
data: {timeout: timeout, pool_filter: pool_filter},
|
||||
data: data,
|
||||
async: async,
|
||||
dataType: "json",
|
||||
success: function(response) {
|
||||
var list;
|
||||
|
@ -24,6 +24,7 @@ define(function(require) {
|
||||
Navigation = require("utils/navigation");
|
||||
|
||||
var RESOURCE = "VM";
|
||||
var VM_MONITORING_CACHE_NAME = 'VM.MONITORING';
|
||||
|
||||
var STATES_STR = [
|
||||
"INIT",
|
||||
@ -541,7 +542,19 @@ define(function(require) {
|
||||
OpenNebulaAction.monitor(params, RESOURCE, false);
|
||||
},
|
||||
"pool_monitor" : function(params) {
|
||||
OpenNebulaAction.monitor(params, RESOURCE, true);
|
||||
if (!Config.isExtendedVmMonitoring) return;
|
||||
|
||||
let process = function(response) {
|
||||
let monitoringPool = response && response["MONITORING_DATA"] && response["MONITORING_DATA"]["MONITORING"];
|
||||
|
||||
return Array.isArray(monitoringPool)
|
||||
? monitoringPool.reduce(function(result, monitoringVM) {
|
||||
return $.extend(result, { [monitoringVM.ID]: monitoringVM })
|
||||
}, {})
|
||||
: {}
|
||||
}
|
||||
|
||||
OpenNebulaAction.list(params, VM_MONITORING_CACHE_NAME, 'vm/monitor', process, undefined, false);
|
||||
},
|
||||
"resize" : function(params) {
|
||||
var action_obj = params.data.extra_param;
|
||||
@ -691,6 +704,25 @@ define(function(require) {
|
||||
}
|
||||
};
|
||||
|
||||
function _getMonitoringPool() {
|
||||
var monitoring = undefined;
|
||||
var cache = OpenNebulaAction.cache(VM_MONITORING_CACHE_NAME);
|
||||
|
||||
if (cache && cache.data) {
|
||||
monitoring = cache.data
|
||||
}
|
||||
|
||||
if (!monitoring || $.isEmptyObject(monitoring)) {
|
||||
VM.pool_monitor({
|
||||
success: function(response) {
|
||||
monitoring = response
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return monitoring || {}
|
||||
}
|
||||
|
||||
function retrieveLastHistoryRecord(element) {
|
||||
if (element.HISTORY_RECORDS && element.HISTORY_RECORDS.HISTORY) {
|
||||
var history = element.HISTORY_RECORDS.HISTORY;
|
||||
@ -787,6 +819,29 @@ define(function(require) {
|
||||
return nics;
|
||||
}
|
||||
|
||||
function getNicsFromMonitoring(element = {}) {
|
||||
let monitoringPool = _getMonitoringPool()
|
||||
let monitoringVM = monitoringPool[element.ID]
|
||||
|
||||
if (!monitoringPool || $.isEmptyObject(monitoringPool) || !monitoringVM) return [];
|
||||
|
||||
return EXTERNAL_IP_ATTRS.reduce(function(externalNics, attr) {
|
||||
let monitoringValues = monitoringVM[attr]
|
||||
|
||||
if (monitoringValues) {
|
||||
$.each(monitoringValues.split(','), function(_, ip) {
|
||||
let exists = externalNics.some(function(nic) { return nic.IP === ip })
|
||||
|
||||
if (!exists) {
|
||||
externalNics.push({ NIC_ID: '_', IP: ip });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return externalNics;
|
||||
}, [])
|
||||
}
|
||||
|
||||
// Return the IP or several IPs of a VM
|
||||
function ipsStr(element, options) {
|
||||
options = $.extend({
|
||||
@ -797,38 +852,21 @@ define(function(require) {
|
||||
}, options)
|
||||
|
||||
var nics = getNICs(element);
|
||||
var monitoring = element && element.MONITORING;
|
||||
var ips = [];
|
||||
|
||||
if (monitoring) {
|
||||
var externalIP;
|
||||
$.each(EXTERNAL_IP_ATTRS, function(index, IPAttr) {
|
||||
externalIP = monitoring[IPAttr];
|
||||
if (externalIP) {
|
||||
var splitArr = externalIP.split(",");
|
||||
$.each(splitArr, function(i,ip){
|
||||
if (ip && ($.inArray(ip, ips) == -1)) {
|
||||
ips.push(ip);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
var nicsFromMonitoring = getNicsFromMonitoring(element)
|
||||
|
||||
nics = nics.concat(nicsFromMonitoring)
|
||||
|
||||
// infoextended: alias will be group by nic
|
||||
if (Config.isExtendedVmInfo || options.forceGroup) {
|
||||
return options.groupStrFunction(element, nics)
|
||||
}
|
||||
|
||||
return (ips.length === 0 && nics && nics.length > 0) ? (
|
||||
$.map(nics, function(nic) {
|
||||
return $.map(NIC_ALIAS_IP_ATTRS, function(attribute) {
|
||||
return nic[attribute]
|
||||
})
|
||||
}).join(options.divider)
|
||||
) : (
|
||||
options.defaultValue
|
||||
)
|
||||
return $.map(nics, function(nic) {
|
||||
return $.map(NIC_ALIAS_IP_ATTRS, function(attribute) {
|
||||
return nic[attribute]
|
||||
})
|
||||
}).join(options.divider) || options.defaultValue
|
||||
};
|
||||
|
||||
// Return a dropdown with all the
|
||||
@ -859,7 +897,7 @@ define(function(require) {
|
||||
|
||||
// Format the other IPs inside a dropdown
|
||||
if (ips.length){
|
||||
html += "<ul class=\"dropdown menu ips-dropdown\" style=\" text-align:left;\" data-dropdown-menu><li><a style=\"padding-top:0em;padding-bottom:0em;padding-left:0em;color:gray\">"+insideHtml+"</a><ul class=\"menu\" style=\"max-height: 50em; overflow: scroll; width:250px;\">";
|
||||
html += "<ul class=\"dropdown menu ips-dropdown\" style=\"white-space: nowrap;text-align:left;\" data-dropdown-menu><li><a style=\"padding-top:0em;padding-bottom:0em;padding-left:0em;color:gray\">"+insideHtml+"</a><ul class=\"menu\" style=\"max-height: 50em; overflow: scroll; width:250px;\">";
|
||||
$.each(ips, function(index, value){
|
||||
html+="<li><a style=\"color:gray\">" + value + "</a></li>";
|
||||
});
|
||||
@ -878,26 +916,34 @@ define(function(require) {
|
||||
copy_nics.unshift(first_nic);
|
||||
|
||||
return copy_nics.reduce(function(column, nic) {
|
||||
identation = " ";
|
||||
var ip = (nic.IP) ? nic.IP : nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL;
|
||||
var nicSection = nic.NIC_ID ? $("<li/>").append($("<a/>").css("color", "gray").html(nic.NIC_ID + ": " + ip)) : $("<li/>").append("<li>").html("-") ;
|
||||
if (nic.IP || (nic.IP6_ULA && nic.IP6_GLOBAL)) {
|
||||
var identation = " ";
|
||||
var ip = (nic.IP) ? nic.IP : nic.IP6_ULA + " " + identation + nic.IP6_GLOBAL;
|
||||
var nicSection = nic.NIC_ID
|
||||
? $("<li/>").append($("<a/>").css("color", "gray").html(nic.NIC_ID + ": " + ip))
|
||||
: $("<li/>").append("<li>").html("-") ;
|
||||
|
||||
if (nic.ALIAS_IDS) {
|
||||
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
|
||||
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
|
||||
? element.TEMPLATE.NIC_ALIAS : [element.TEMPLATE.NIC_ALIAS];
|
||||
var alias = templateAlias.find(function(alias) { return alias.NIC_ID === aliasId; });
|
||||
column.append(nicSection)
|
||||
|
||||
if (alias) {
|
||||
var alias_ip = alias.IP ? alias.IP : alias.IP6_ULA + " " + identation + "> " + alias.IP6_GLOBAL;
|
||||
nicSection.append($("<li/>").append($("<a/>").css({
|
||||
"color": "gray",
|
||||
"font-style": "italic",
|
||||
}).html(identation + "> " + alias_ip))); }
|
||||
});
|
||||
if (nic.ALIAS_IDS) {
|
||||
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
|
||||
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
|
||||
? element.TEMPLATE.NIC_ALIAS : [element.TEMPLATE.NIC_ALIAS];
|
||||
|
||||
var alias = templateAlias.find(function(alias) { return alias.NIC_ID === aliasId; });
|
||||
|
||||
if (alias) {
|
||||
var alias_ip = alias.IP ? alias.IP : alias.IP6_ULA + " " + identation + "> " + alias.IP6_GLOBAL;
|
||||
column.append($("<li/>").append($("<a/>").css({
|
||||
"color": "gray",
|
||||
"font-style": "italic",
|
||||
}).html(identation + "> " + alias_ip)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return column.append(nicSection);
|
||||
return column;
|
||||
}, $("<div/>")).html();
|
||||
};
|
||||
|
||||
@ -905,27 +951,30 @@ define(function(require) {
|
||||
var identation = " ";
|
||||
|
||||
return nics.reduce(function(column, nic) {
|
||||
var ip = nic.IP || nic.IP6_ULA + "<br>" + identation + nic.IP6_GLOBAL
|
||||
if (nic.IP || (nic.IP6_ULA && nic.IP6_GLOBAL)) {
|
||||
var ip = nic.IP || nic.IP6_ULA + "<br>" + identation + nic.IP6_GLOBAL
|
||||
|
||||
column.append($("<p/>").css("margin-bottom", 0).html(nic.NIC_ID + ": " + ip))
|
||||
column.append($("<p/>").css("margin-bottom", 0).html(nic.NIC_ID + ": " + ip))
|
||||
|
||||
if (nic.ALIAS_IDS) {
|
||||
if (nic.ALIAS_IDS) {
|
||||
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
|
||||
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
|
||||
? element.TEMPLATE.NIC_ALIAS : [element.TEMPLATE.NIC_ALIAS];
|
||||
|
||||
nic.ALIAS_IDS.split(",").forEach(function(aliasId) {
|
||||
var templateAlias = Array.isArray(element.TEMPLATE.NIC_ALIAS)
|
||||
? element.TEMPLATE.NIC_ALIAS : [element.TEMPLATE.NIC_ALIAS];
|
||||
var alias = templateAlias.find(function(alias) { return alias.NIC_ID === aliasId; });
|
||||
var alias = templateAlias.find(function(alias) { return alias.NIC_ID === aliasId; });
|
||||
|
||||
if (alias) {
|
||||
var alias_ip = alias.IP
|
||||
? identation + "> " + alias.IP
|
||||
: alias.IP6_ULA + "<br>" + identation + "> " + alias.IP6_GLOBAL;
|
||||
if (alias) {
|
||||
var alias_ip = alias.IP
|
||||
? identation + "> " + alias.IP
|
||||
: alias.IP6_ULA + "<br>" + identation + "> " + alias.IP6_GLOBAL;
|
||||
|
||||
column.append($("<p/>").css({
|
||||
"margin-bottom": 0,
|
||||
"font-style": "italic",
|
||||
}).html(alias_ip)); }
|
||||
});
|
||||
column.append($("<p/>").css({
|
||||
"margin-bottom": 0,
|
||||
"font-style": "italic",
|
||||
}).html(alias_ip));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return column;
|
||||
|
@ -183,6 +183,10 @@ define(function(require) {
|
||||
"high":_config["user_config"]["threshold_high"]
|
||||
},
|
||||
"isExtendedVmInfo": _config["system_config"] && _config["system_config"]["get_extended_vm_info"] && _config["system_config"]["get_extended_vm_info"] === "true",
|
||||
"isExtendedVmMonitoring":
|
||||
_config["system_config"] &&
|
||||
_config["system_config"]["get_extended_vm_monitoring"] &&
|
||||
_config["system_config"]["get_extended_vm_monitoring"] === "true",
|
||||
"isLogEnabled": _config["zone_id"] === _config["id_own_federation"] ? true : false,
|
||||
};
|
||||
|
||||
|
@ -42,6 +42,11 @@ define(function(require) {
|
||||
|
||||
var _actions = {
|
||||
"VM.list": _commonActions.list(),
|
||||
"VM.pool_monitor": {
|
||||
type: "single",
|
||||
call: OpenNebulaVM.pool_monitor,
|
||||
error: Notifier.onError
|
||||
},
|
||||
"VM.show": {
|
||||
type: "single",
|
||||
call: OpenNebulaVM.show,
|
||||
|
@ -142,6 +142,8 @@ define(function(require) {
|
||||
StateActions.disableAllStateActions();
|
||||
}
|
||||
|
||||
Sunstone.runAction('VM.pool_monitor')
|
||||
|
||||
this.totalVms = 0;
|
||||
this.activeVms = 0;
|
||||
this.pendingVms = 0;
|
||||
|
@ -823,9 +823,7 @@ end
|
||||
##############################################################################
|
||||
|
||||
get '/:resource/monitor' do
|
||||
@SunstoneServer.get_pool_monitoring(
|
||||
params[:resource],
|
||||
params[:monitor_resources])
|
||||
@SunstoneServer.get_pool_monitoring(params[:resource])
|
||||
end
|
||||
|
||||
get '/user/:id/monitor' do
|
||||
|
@ -52,7 +52,8 @@
|
||||
'max_upload_file_size' : <%= $conf[:max_upload_file_size] ? $conf[:max_upload_file_size] : "undefined" %>,
|
||||
'leases' : <%= $conf[:leases] ? $conf[:leases].to_json : "null" %>,
|
||||
'mapped_ips' : '<%= $conf[:mapped_ips] ? $conf[:mapped_ips] : false %>',
|
||||
'get_extended_vm_info': '<%= $conf[:get_extended_vm_info] ? $conf[:get_extended_vm_info] : false %>'
|
||||
'get_extended_vm_info': '<%= $conf[:get_extended_vm_info] ? $conf[:get_extended_vm_info] : false %>',
|
||||
'get_extended_vm_monitoring': '<%= $conf[:get_extended_vm_monitoring] ? $conf[:get_extended_vm_monitoring] : false %>'
|
||||
},
|
||||
'view' : view,
|
||||
'available_views' : available_views,
|
||||
|
Loading…
x
Reference in New Issue
Block a user