mirror of
https://github.com/OpenNebula/one.git
synced 2025-08-14 05:49:26 +03:00
F #6885: Add lxc forecast probes
co-authored-by: Marco Mancini <mmancini@opennebula.io>
This commit is contained in:
@ -1344,6 +1344,7 @@ IM_PROBES_LXC_HOST_BEACON_FILES="\
|
||||
|
||||
IM_PROBES_LXC_HOST_MONITOR_FILES="\
|
||||
src/im_mad/remotes/lxc-probes.d/host/monitor/linux_usage.rb \
|
||||
src/im_mad/remotes/lxc-probes.d/host/monitor/prediction.sh \
|
||||
src/im_mad/remotes/lxc-probes.d/host/monitor/numa_usage.rb"
|
||||
|
||||
IM_PROBES_LXC_HOST_SYSTEM_FILES="\
|
||||
@ -1364,6 +1365,7 @@ IM_PROBES_LXC_VM_STATUS_FILES="\
|
||||
src/im_mad/remotes/lxc-probes.d/vm/status/state.rb"
|
||||
|
||||
IM_PROBES_ETC_LXC_PROBES_FILES="\
|
||||
src/im_mad/remotes/lxc-probes.d/forecast.conf \
|
||||
src/im_mad/remotes/lib/probe_db.conf"
|
||||
|
||||
IM_PROBES_VCENTER_FILES="src/im_mad/remotes/vcenter.d/monitord-client_control.sh"
|
||||
|
@ -1,13 +0,0 @@
|
||||
# This section is related to the configuration for DB retention and forecast period
|
||||
# related to the hosts
|
||||
host:
|
||||
db_retention: 4 # Number of weeks
|
||||
forecast_period: 5 # Number of minutes
|
||||
forecast_far_period: 720 # Number of hours
|
||||
|
||||
# This section is related to the configuration for DB retention and forecast
|
||||
# related to the virtual machines
|
||||
virtualmachine:
|
||||
db_retention: 2 # Number of weeks
|
||||
forecast_period: 5 # Number of minutes
|
||||
forecast_far_period: 48 # Number of hours
|
1
src/im_mad/remotes/kvm-probes.d/forecast.conf
Symbolic link
1
src/im_mad/remotes/kvm-probes.d/forecast.conf
Symbolic link
@ -0,0 +1 @@
|
||||
../node-probes.d/forecast.conf
|
@ -22,12 +22,12 @@ require_relative '../../../lib/linux'
|
||||
|
||||
xml_txt = STDIN.read
|
||||
|
||||
LinuxHost.usage('kvm')
|
||||
host = LinuxHost.usage('kvm')
|
||||
|
||||
begin
|
||||
config = REXML::Document.new(xml_txt).root
|
||||
hostid = config.elements['HOST_ID'].text.to_s
|
||||
|
||||
LinuxHost.to_sql(hostid)
|
||||
host.to_sql(hostid)
|
||||
rescue StandardError
|
||||
end
|
||||
|
@ -1,41 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2024, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
STDIN=`cat -`
|
||||
|
||||
PYTHON_PATH=/var/tmp/one/im/lib/python
|
||||
|
||||
PYTHON_VERSION=$(python3 --version | cut -d ' ' -f2)
|
||||
|
||||
MAJOR=$(echo "$PYTHON_VERSION" | cut -d. -f1)
|
||||
MINOR=$(echo "$PYTHON_VERSION" | cut -d. -f2)
|
||||
|
||||
if [[ "$MAJOR" -lt 3 ]] || [[ "$MAJOR" -eq 3 && "$MINOR" -lt 9 ]]; then
|
||||
if command -v python3.9 &>/dev/null; then
|
||||
PYTHON=python3.9
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
PYTHON=python3
|
||||
fi
|
||||
|
||||
HOST_ID=$(echo "${STDIN}" | xmllint --xpath 'string(//HOST_ID)' -)
|
||||
ENTITYH="host,${HOST_ID},0,/var/tmp/one_db"
|
||||
|
||||
PYTHONPATH=$PYTHON_PATH $PYTHON $PYTHON_PATH/prediction.py --entity $ENTITYH --pythonpath $PYTHON_PATH
|
1
src/im_mad/remotes/kvm-probes.d/host/monitor/prediction.sh
Symbolic link
1
src/im_mad/remotes/kvm-probes.d/host/monitor/prediction.sh
Symbolic link
@ -0,0 +1 @@
|
||||
../../../node-probes.d/prediction.sh
|
@ -171,9 +171,23 @@ class LinuxHost
|
||||
|
||||
print_info('NETRX', linux.net[:rx])
|
||||
print_info('NETTX', linux.net[:tx])
|
||||
|
||||
linux
|
||||
end
|
||||
|
||||
def self.store_metric_db(db, host_id, metric_name, timestamp, value)
|
||||
def self.config(hypervisor)
|
||||
linux = new
|
||||
|
||||
print_info('HYPERVISOR', hypervisor)
|
||||
|
||||
print_info('TOTALCPU', linux.cpu[:total])
|
||||
print_info('CPUSPEED', linux.cpu[:speed])
|
||||
|
||||
print_info('TOTALMEMORY', linux.memory[:total])
|
||||
print_info('CGROUPS_VERSION', linux.cgversion) unless linux.cgversion.empty?
|
||||
end
|
||||
|
||||
def store_metric_db(db, host_id, metric_name, timestamp, value)
|
||||
table_name = "host_#{host_id}_#{metric_name}_monitoring"
|
||||
|
||||
create_table_query = <<-SQL
|
||||
@ -201,31 +215,17 @@ class LinuxHost
|
||||
db.execute(insert_query, [timestamp, value])
|
||||
end
|
||||
|
||||
def self.to_sql(host_id)
|
||||
linux = new
|
||||
|
||||
def to_sql(host_id)
|
||||
FileUtils.mkdir_p(DB_PATH)
|
||||
|
||||
db = SQLite3::Database.new(File.join(DB_PATH, DB_NAME))
|
||||
timestamp = Time.now.to_i
|
||||
|
||||
DB_MONITOR_KEYS.each do |k,v|
|
||||
self.store_metric_db(db, host_id, k, timestamp, v.call(linux))
|
||||
store_metric_db(db, host_id, k, timestamp, v.call(self))
|
||||
end
|
||||
|
||||
db.close
|
||||
end
|
||||
|
||||
def self.config(hypervisor)
|
||||
linux = new
|
||||
|
||||
print_info('HYPERVISOR', hypervisor)
|
||||
|
||||
print_info('TOTALCPU', linux.cpu[:total])
|
||||
print_info('CPUSPEED', linux.cpu[:speed])
|
||||
|
||||
print_info('TOTALMEMORY', linux.memory[:total])
|
||||
print_info('CGROUPS_VERSION', linux.cgversion) unless linux.cgversion.empty?
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -21,6 +21,7 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../vmm/lxc/"
|
||||
require 'json'
|
||||
require 'base64'
|
||||
require 'client'
|
||||
require 'sqlite3'
|
||||
|
||||
require_relative 'process_list'
|
||||
require_relative 'domain'
|
||||
@ -136,6 +137,21 @@ end
|
||||
#-------------------------------------------------------------------------------
|
||||
class Domain < BaseDomain
|
||||
|
||||
DB_PATH = '/var/tmp/one_db'
|
||||
|
||||
def initialize(name)
|
||||
super(name)
|
||||
|
||||
@predictions = true
|
||||
|
||||
path = "#{__dir__}/../../etc/im/lxc-probes.d/forecast.conf"
|
||||
conf = YAML.load_file(path)
|
||||
|
||||
@db_retention = Integer(conf['vm']['db_retention'])
|
||||
rescue StandardError
|
||||
@db_retention = 4
|
||||
end
|
||||
|
||||
# Gets the information of the domain, fills the @vm hash using ProcessList
|
||||
# and ps command
|
||||
def info
|
||||
@ -171,6 +187,22 @@ class Domain < BaseDomain
|
||||
io_stats(hash)
|
||||
end
|
||||
|
||||
# Compute forecast values for the VM metrics
|
||||
def predictions
|
||||
base = '/var/tmp/one/im/lib/python/prediction.sh'
|
||||
cmd = "#{base} --entity virtualmachine,#{@vm[:id]},#{@vm[:uuid]},#{DB_PATH}"
|
||||
|
||||
o, _e, s = Open3.capture3 cmd
|
||||
|
||||
if s.success?
|
||||
o
|
||||
else
|
||||
''
|
||||
end
|
||||
rescue StandardError
|
||||
''
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
@ -226,6 +258,7 @@ module DomainList
|
||||
domains = LXCDomains.new
|
||||
|
||||
domains.info
|
||||
domains.to_sql
|
||||
domains.to_monitor
|
||||
end
|
||||
|
||||
|
1
src/im_mad/remotes/lxc-probes.d/forecast.conf
Symbolic link
1
src/im_mad/remotes/lxc-probes.d/forecast.conf
Symbolic link
@ -0,0 +1 @@
|
||||
../node-probes.d/forecast.conf
|
@ -16,6 +16,18 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'rexml/document'
|
||||
|
||||
require_relative '../../../lib/linux'
|
||||
|
||||
LinuxHost.usage('lxc')
|
||||
xml_txt = STDIN.read
|
||||
|
||||
host = LinuxHost.usage('lxc')
|
||||
|
||||
begin
|
||||
config = REXML::Document.new(xml_txt).root
|
||||
hostid = config.elements['HOST_ID'].text.to_s
|
||||
|
||||
host.to_sql(hostid)
|
||||
rescue StandardError
|
||||
end
|
||||
|
1
src/im_mad/remotes/lxc-probes.d/host/monitor/prediction.sh
Symbolic link
1
src/im_mad/remotes/lxc-probes.d/host/monitor/prediction.sh
Symbolic link
@ -0,0 +1 @@
|
||||
../../../node-probes.d/prediction.sh
|
13
src/im_mad/remotes/node-probes.d/forecast.conf
Normal file
13
src/im_mad/remotes/node-probes.d/forecast.conf
Normal file
@ -0,0 +1,13 @@
|
||||
# This section is related to the configuration for DB retention and forecast period
|
||||
# related to the hosts
|
||||
host:
|
||||
db_retention: 4 # Number of weeks
|
||||
forecast_period: 5 # Number of minutes
|
||||
forecast_far_period: 720 # Number of hours
|
||||
|
||||
# This section is related to the configuration for DB retention and forecast
|
||||
# related to the virtual machines
|
||||
virtualmachine:
|
||||
db_retention: 2 # Number of weeks
|
||||
forecast_period: 5 # Number of minutes
|
||||
forecast_far_period: 48 # Number of hours
|
41
src/im_mad/remotes/node-probes.d/prediction.sh
Executable file
41
src/im_mad/remotes/node-probes.d/prediction.sh
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2024, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
STDIN=`cat -`
|
||||
|
||||
PYTHON_PATH=/var/tmp/one/im/lib/python
|
||||
|
||||
PYTHON_VERSION=$(python3 --version | cut -d ' ' -f2)
|
||||
|
||||
MAJOR=$(echo "$PYTHON_VERSION" | cut -d. -f1)
|
||||
MINOR=$(echo "$PYTHON_VERSION" | cut -d. -f2)
|
||||
|
||||
if [[ "$MAJOR" -lt 3 ]] || [[ "$MAJOR" -eq 3 && "$MINOR" -lt 9 ]]; then
|
||||
if command -v python3.9 &>/dev/null; then
|
||||
PYTHON=python3.9
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
PYTHON=python3
|
||||
fi
|
||||
|
||||
HOST_ID=$(echo "${STDIN}" | xmllint --xpath 'string(//HOST_ID)' -)
|
||||
ENTITYH="host,${HOST_ID},0,/var/tmp/one_db"
|
||||
|
||||
PYTHONPATH=$PYTHON_PATH $PYTHON $PYTHON_PATH/prediction.py --entity $ENTITYH --pythonpath $PYTHON_PATH
|
Reference in New Issue
Block a user