mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-08 21:16:39 +09:00
F #4901: Updates MEM & CPU when RESERVED_ attributes are updated. Adds TOTAL_CPU
and TOTAL_MEM shares to store raw monitoring cpu/mem metrics. Adds migrator and increases local DB version number.
This commit is contained in:
1 parent
09825bd7ba
commit
08d88e0119
8 files changed
+211
-12
No files matched your search
+15
-2
@@ -318,6 +318,9 @@ public:
|
||||
*/
|
||||
void reset_capacity()
|
||||
{
|
||||
total_cpu = 0;
|
||||
total_mem = 0;
|
||||
|
||||
max_cpu = 0;
|
||||
max_mem = 0;
|
||||
|
||||
@@ -342,6 +345,13 @@ public:
|
||||
*/
|
||||
void set_capacity(Host *host, const string& crcpu, const string& crmem);
|
||||
|
||||
/**
|
||||
* Update the capacity attributes when the RESERVED_CPU and RESERVED_MEM
|
||||
* are updated.
|
||||
* @param host for this share
|
||||
*/
|
||||
void update_capacity(Host *host);
|
||||
|
||||
/**
|
||||
* Return the number of running VMs in this host
|
||||
*/
|
||||
@@ -356,9 +366,12 @@ private:
|
||||
long long mem_usage; /**< Memory allocated to VMs (in KB) */
|
||||
long long cpu_usage; /**< CPU allocated to VMs (in percentage) */
|
||||
|
||||
long long total_mem; /**< Total memory capacity (in KB) */
|
||||
long long total_cpu; /**< Total cpu capacity (in percentage) */
|
||||
|
||||
long long max_disk; /**< Total disk capacity (in MB) */
|
||||
long long max_mem; /**< Total memory capacity (in KB) */
|
||||
long long max_cpu; /**< Total cpu capacity (in percentage) */
|
||||
long long max_mem; /**< Total memory capacity (in KB) +/- reserved */
|
||||
long long max_cpu; /**< Total cpu capacity (in percentage) +/- reserved*/
|
||||
|
||||
long long free_disk; /**< Free disk from the IM monitor */
|
||||
long long free_mem; /**< Free memory from the IM monitor */
|
||||
|
||||
+1
-1
@@ -353,7 +353,7 @@ public:
|
||||
*/
|
||||
static string local_db_version()
|
||||
{
|
||||
return "4.90.0";
|
||||
return "5.2.0";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-2
@@ -1155,13 +1155,15 @@ ONEDB_SHARED_MIGRATOR_FILES="src/onedb/shared/2.0_to_2.9.80.rb \
|
||||
src/onedb/shared/4.11.80_to_4.90.0.rb \
|
||||
src/onedb/shared/4.90.0_to_5.2.0.rb"
|
||||
|
||||
ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/4.5.80_to_4.7.80.rb \
|
||||
ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/db_schema.rb \
|
||||
src/onedb/local/4.5.80_to_4.7.80.rb \
|
||||
src/onedb/local/4.7.80_to_4.9.80.rb \
|
||||
src/onedb/local/4.9.80_to_4.10.3.rb \
|
||||
src/onedb/local/4.10.3_to_4.11.80.rb \
|
||||
src/onedb/local/4.11.80_to_4.13.80.rb \
|
||||
src/onedb/local/4.13.80_to_4.13.85.rb \
|
||||
src/onedb/local/4.13.85_to_4.90.0.rb"
|
||||
src/onedb/local/4.13.85_to_4.90.0.rb \
|
||||
src/onedb/local/4.90.0_to_5.2.0.rb"
|
||||
|
||||
ONEDB_PATCH_FILES="src/onedb/patches/4.14_monitoring.rb \
|
||||
src/onedb/patches/history_times.rb"
|
||||
|
||||
@@ -382,14 +382,19 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "HOST SHARES", false)
|
||||
|
||||
puts str % ["TOTAL MEM", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM'].to_i, {})]
|
||||
puts str % ["USED MEM (REAL)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM'].to_i, {})]
|
||||
puts str % ["USED MEM (ALLOCATED)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE'].to_i, {})]
|
||||
puts str % ["TOTAL CPU", host['HOST_SHARE/MAX_CPU']]
|
||||
puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']]
|
||||
puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
|
||||
puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MEMORY", false)
|
||||
puts str % [" TOTAL", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/TOTAL_MEM'].to_i, {})]
|
||||
puts str % [" TOTAL +/- RESERVED", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM'].to_i, {})]
|
||||
puts str % [" USED (REAL)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM'].to_i, {})]
|
||||
puts str % [" USED (ALLOCATED)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE'].to_i, {})]
|
||||
|
||||
CLIHelper.print_header(str_h1 % "CPU", false)
|
||||
puts str % [" TOTAL", host['HOST_SHARE/TOTAL_CPU']]
|
||||
puts str % [" TOTAL +/- RESERVED", host['HOST_SHARE/MAX_CPU']]
|
||||
puts str % [" USED (REAL)", host['HOST_SHARE/USED_CPU']]
|
||||
puts str % [" USED (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
|
||||
puts
|
||||
|
||||
datastores = host.to_hash['HOST']['HOST_SHARE']['DATASTORES']['DS']
|
||||
|
||||
@@ -740,5 +740,7 @@ int Host::post_update_template(string& error)
|
||||
replace_template_attribute("IM_MAD", im_mad_name);
|
||||
replace_template_attribute("VM_MAD", vmm_mad_name);
|
||||
|
||||
host_share.update_capacity(this);
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -376,6 +376,7 @@ ostream& operator<<(ostream& os, const HostSharePCI& pci)
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* HostShare :: Constructor/Destructor */
|
||||
/* ************************************************************************ */
|
||||
@@ -385,6 +386,8 @@ HostShare::HostShare(long long _max_disk,long long _max_mem,long long _max_cpu):
|
||||
disk_usage(0),
|
||||
mem_usage(0),
|
||||
cpu_usage(0),
|
||||
total_mem(_max_mem),
|
||||
total_cpu(_max_cpu),
|
||||
max_disk(_max_disk),
|
||||
max_mem(_max_mem),
|
||||
max_cpu(_max_cpu),
|
||||
@@ -417,6 +420,8 @@ string& HostShare::to_xml(string& xml) const
|
||||
<< "<DISK_USAGE>" << disk_usage << "</DISK_USAGE>"
|
||||
<< "<MEM_USAGE>" << mem_usage << "</MEM_USAGE>"
|
||||
<< "<CPU_USAGE>" << cpu_usage << "</CPU_USAGE>"
|
||||
<< "<TOTAL_MEM>" << total_mem << "</TOTAL_MEM>"
|
||||
<< "<TOTAL_CPU>" << total_cpu << "</TOTAL_CPU>"
|
||||
<< "<MAX_DISK>" << max_disk << "</MAX_DISK>"
|
||||
<< "<MAX_MEM>" << max_mem << "</MAX_MEM>"
|
||||
<< "<MAX_CPU>" << max_cpu << "</MAX_CPU>"
|
||||
@@ -451,6 +456,9 @@ int HostShare::from_xml_node(const xmlNodePtr node)
|
||||
rc += xpath<long long>(mem_usage, "/HOST_SHARE/MEM_USAGE", -1);
|
||||
rc += xpath<long long>(cpu_usage, "/HOST_SHARE/CPU_USAGE", -1);
|
||||
|
||||
rc += xpath<long long>(total_mem , "/HOST_SHARE/TOTAL_MEM", -1);
|
||||
rc += xpath<long long>(total_cpu, "/HOST_SHARE/TOTAL_CPU", -1);
|
||||
|
||||
rc += xpath<long long>(max_disk, "/HOST_SHARE/MAX_DISK", -1);
|
||||
rc += xpath<long long>(max_mem , "/HOST_SHARE/MAX_MEM", -1);
|
||||
rc += xpath<long long>(max_cpu , "/HOST_SHARE/MAX_CPU", -1);
|
||||
@@ -593,9 +601,11 @@ void HostShare::set_capacity(Host *host, const string& cluster_rcpu,
|
||||
}
|
||||
|
||||
host->erase_template_attribute("TOTALCPU", val);
|
||||
total_cpu = val;
|
||||
set_reserved_metric(max_cpu, val, host_rcpu);
|
||||
|
||||
host->erase_template_attribute("TOTALMEMORY", val);
|
||||
total_mem = val;
|
||||
set_reserved_metric(max_mem, val, host_rmem);
|
||||
|
||||
host->erase_template_attribute("DS_LOCATION_TOTAL_MB", val);
|
||||
@@ -620,6 +630,20 @@ void HostShare::set_capacity(Host *host, const string& cluster_rcpu,
|
||||
used_disk = val;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void HostShare::update_capacity(Host *host)
|
||||
{
|
||||
string host_rcpu;
|
||||
string host_rmem;
|
||||
|
||||
host->get_reserved_capacity(host_rcpu, host_rmem);
|
||||
|
||||
set_reserved_metric(max_cpu, total_cpu, host_rcpu);
|
||||
|
||||
set_reserved_metric(max_mem, total_mem, host_rmem);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
require 'set'
|
||||
require 'base64'
|
||||
require 'zlib'
|
||||
require 'pathname'
|
||||
|
||||
require 'opennebula'
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
require 'db_schema'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
module Migrator
|
||||
def db_version
|
||||
"5.2.0"
|
||||
end
|
||||
|
||||
def one_version
|
||||
"OpenNebula 5.2.0"
|
||||
end
|
||||
|
||||
def up
|
||||
init_log_time()
|
||||
|
||||
feature_4901()
|
||||
|
||||
log_time()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def xpath(doc, sxpath)
|
||||
element = doc.root.at_xpath(sxpath)
|
||||
if !element.nil?
|
||||
element.text
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# Feature 4921. Adds TOTAL_CPU and TOTAL_MEM to HOST/HOST_SHARE to compute
|
||||
# MAX_CPU and MAX_MEM when RESERVED_CPU/MEM is updated
|
||||
############################################################################
|
||||
def feature_4901
|
||||
@db.run "ALTER TABLE host_pool RENAME TO old_host_pool;"
|
||||
@db.run host_pool_schema()
|
||||
|
||||
@db.transaction do
|
||||
@db.fetch("SELECT * FROM old_host_pool") do |row|
|
||||
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c|
|
||||
c.default_xml.noblanks
|
||||
}
|
||||
|
||||
rcpu = xpath(doc, "TEMPLATE/RESERVED_CPU").to_i
|
||||
rmem = xpath(doc, "TEMPLATE/RESERVED_MEM").to_i
|
||||
|
||||
total_cpu = xpath(doc, "HOST_SHARE/MAX_CPU").to_i + rcpu
|
||||
total_mem = xpath(doc, "HOST_SHARE/MAX_MEM").to_i + rmem
|
||||
|
||||
total_cpu_e = doc.create_element "TOTAL_CPU", total_cpu
|
||||
total_mem_e = doc.create_element "TOTAL_MEM", total_mem
|
||||
|
||||
host_share = doc.root.at_xpath("HOST_SHARE")
|
||||
host_share.add_child(total_cpu_e)
|
||||
host_share.add_child(total_mem_e)
|
||||
|
||||
@db[:host_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => doc.root.to_s,
|
||||
:state => row[:state],
|
||||
:last_mon_time => row[:last_mon_time],
|
||||
:uid => row[:uid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u],
|
||||
:cid => row[:cid])
|
||||
end
|
||||
end
|
||||
|
||||
@db.run "DROP TABLE old_host_pool;"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,48 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'set'
|
||||
require 'base64'
|
||||
require 'zlib'
|
||||
require 'pathname'
|
||||
|
||||
require 'opennebula'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
module Migrator
|
||||
##############################################################################
|
||||
# DB schema for OpenNebula tables, each function may return the schema for
|
||||
# each opennebula version
|
||||
##############################################################################
|
||||
def host_pool_schema
|
||||
case db_version()
|
||||
when "4.5.80"
|
||||
when "4.7.80"
|
||||
when "4.9.80"
|
||||
when "4.10.3"
|
||||
when "4.11.80"
|
||||
when "4.13.80"
|
||||
when "4.13.85"
|
||||
when "4.90.0"
|
||||
when "5.2.0"
|
||||
'CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), '\
|
||||
'body MEDIUMTEXT, state INTEGER, last_mon_time INTEGER, uid INTEGER, '\
|
||||
'gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, '\
|
||||
'cid INTEGER);'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user