From 954ff1a4fc1bd4326311b9948e1a7fbd4b5b873b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 11 Jul 2011 16:08:26 +0200 Subject: [PATCH] Remove OneMonitor tool from source tree, sunstone-server script and install script. This tool is replaced by acctd. --- install.sh | 12 -- src/sunstone/bin/sunstone-server | 43 ------- src/sunstone/share/OneMonitor/HostMonitor.rb | 62 ---------- src/sunstone/share/OneMonitor/OneMonitor.rb | 112 ------------------ .../share/OneMonitor/OneMonitorClient.rb | 35 ------ .../share/OneMonitor/OneMonitorClientUtils.rb | 40 ------- .../share/OneMonitor/OneMonitorUtils.rb | 93 --------------- src/sunstone/share/OneMonitor/VMMonitor.rb | 54 --------- .../share/OneMonitor/runOneMonitor.rb | 41 ------- 9 files changed, 492 deletions(-) delete mode 100644 src/sunstone/share/OneMonitor/HostMonitor.rb delete mode 100644 src/sunstone/share/OneMonitor/OneMonitor.rb delete mode 100644 src/sunstone/share/OneMonitor/OneMonitorClient.rb delete mode 100644 src/sunstone/share/OneMonitor/OneMonitorClientUtils.rb delete mode 100644 src/sunstone/share/OneMonitor/OneMonitorUtils.rb delete mode 100644 src/sunstone/share/OneMonitor/VMMonitor.rb delete mode 100755 src/sunstone/share/OneMonitor/runOneMonitor.rb diff --git a/install.sh b/install.sh index d17be6f113..5149562027 100755 --- a/install.sh +++ b/install.sh @@ -222,8 +222,6 @@ SUNSTONE_DIRS="$SUNSTONE_LOCATION/models \ $SUNSTONE_LOCATION/public/vendor/jQuery \ $SUNSTONE_LOCATION/public/vendor/jGrowl \ $SUNSTONE_LOCATION/public/vendor/flot \ - $SUNSTONE_LOCATION/share \ - $SUNSTONE_LOCATION/share/OneMonitor \ $SUNSTONE_LOCATION/public/images \ $SUNSTONE_LOCATION/templates \ $SUNSTONE_LOCATION/views" @@ -341,7 +339,6 @@ INSTALL_SUNSTONE_FILES=( SUNSTONE_PUBLIC_VENDOR_JQUERYUI:$SUNSTONE_LOCATION/public/vendor/jQueryUI SUNSTONE_PUBLIC_VENDOR_JQUERYLAYOUT:$SUNSTONE_LOCATION/public/vendor/jQueryLayout SUNSTONE_PUBLIC_VENDOR_FLOT:$SUNSTONE_LOCATION/public/vendor/flot - SUNSTONE_SHARE_ONEMONITOR:$SUNSTONE_LOCATION/share/OneMonitor SUNSTONE_PUBLIC_IMAGES_FILES:$SUNSTONE_LOCATION/public/images ) @@ -896,15 +893,6 @@ src/sunstone/public/vendor/flot/LICENSE.txt \ src/sunstone/public/vendor/flot/NOTICE \ src/sunstone/public/vendor/flot/README.txt" -SUNSTONE_SHARE_ONEMONITOR="\ -src/sunstone/share/OneMonitor/HostMonitor.rb \ -src/sunstone/share/OneMonitor/OneMonitorClient.rb \ -src/sunstone/share/OneMonitor/OneMonitorClientUtils.rb \ -src/sunstone/share/OneMonitor/OneMonitor.rb \ -src/sunstone/share/OneMonitor/OneMonitorUtils.rb \ -src/sunstone/share/OneMonitor/runOneMonitor.rb \ -src/sunstone/share/OneMonitor/VMMonitor.rb" - SUNSTONE_PUBLIC_IMAGES_FILES="src/sunstone/public/images/ajax-loader.gif \ src/sunstone/public/images/login_over.png \ src/sunstone/public/images/login.png \ diff --git a/src/sunstone/bin/sunstone-server b/src/sunstone/bin/sunstone-server index 7973c20045..74ad261176 100755 --- a/src/sunstone/bin/sunstone-server +++ b/src/sunstone/bin/sunstone-server @@ -23,22 +23,12 @@ if [ -z "$ONE_LOCATION" ]; then SUNSTONE_LOCK_FILE=/var/lock/one/.sunstone.lock SUNSTONE_LOG=/var/log/one/sunstone.log SUNSTONE_CONF=/etc/one/sunstone-server.conf - ONEMONITOR_CMD=/usr/lib/one/sunstone/share/OneMonitor/runOneMonitor.rb - ONEMONITOR_PID=/var/run/one/onemonitor.pid - ONEMONITOR_LOG=/var/log/one/onemonitor.log - HOST_LOG_FOLDER=/var/log/one/OneMonitor/host - VM_LOG_FOLDER=/var/log/one/OneMonitor/vm else SUNSTONE_PID=$ONE_LOCATION/var/sunstone.pid SUNSTONE_SERVER=$ONE_LOCATION/lib/sunstone/config.ru SUNSTONE_LOCK_FILE=$ONE_LOCATION/var/.sunstone.lock SUNSTONE_LOG=$ONE_LOCATION/var/sunstone.log SUNSTONE_CONF=$ONE_LOCATION/etc/sunstone-server.conf - ONEMONITOR_CMD=$ONE_LOCATION/lib/sunstone/share/OneMonitor/runOneMonitor.rb - ONEMONITOR_PID=$ONE_LOCATION/var/onemonitor.pid - ONEMONITOR_LOG=$ONE_LOCATION/var/onemonitor.log - HOST_LOG_FOLDER=$ONE_LOCATION/var/OneMonitor/host - VM_LOG_FOLDER=$ONE_LOCATION/var/OneMonitor/vm fi setup() @@ -94,35 +84,6 @@ start() fi echo "sunstone-server listening on $HOST:$PORT" - - # Start the monitoring app - if [ ! -d $HOST_LOG_FOLDER ] - then - mkdir -p $HOST_LOG_FOLDER - [[ $? -ne 0 ]] && ( echo "Error creating host log directory"; exit 1 ) - fi - - if [ ! -d $VM_LOG_FOLDER ] - then - mkdir -p $VM_LOG_FOLDER - [[ $? -ne 0 ]] && ( echo "Error creating vm log directory"; exit 1 ) - fi - - if [ -z $MONITORING_INTERVAL ] - then - MONITORING_INTERVAL=600 - fi - - ruby $ONEMONITOR_CMD $MONITORING_INTERVAL $HOST_LOG_FOLDER $VM_LOG_FOLDER &> $ONEMONITOR_LOG & - LASTPID=$! - - sleep 1 - ps $LASTPID &> /dev/null - - [[ $? -ne 0 ]] && ( echo "Error launching monitoring daemon"; exit 1 ) - - echo -n $LASTPID > $ONEMONITOR_PID - echo "OneMonitor monitoring tool launched" } # @@ -142,10 +103,6 @@ stop() rm -f $SUNSTONE_LOCK_FILE &> /dev/null echo "sunstone-server stopped" - - kill -KILL `cat $ONEMONITOR_PID` &> /dev/null - - echo "OneMonitor tool stopped" } case "$1" in diff --git a/src/sunstone/share/OneMonitor/HostMonitor.rb b/src/sunstone/share/OneMonitor/HostMonitor.rb deleted file mode 100644 index be0e8f37f3..0000000000 --- a/src/sunstone/share/OneMonitor/HostMonitor.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -------------------------------------------------------------------------- # -# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # -# # -# 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 'OneMonitor' - -class HostMonitor < OneMonitor - #:time, :id labels - HOST_MONITORING_ELEMS = { - :time => "LAST_MON_TIME", - :id => "ID", - :name => "NAME", - :state => "STATE", - :cluster => "CLUSTER", - :disk_usage => "HOST_SHARE/DISK_USAGE", - :cpu_usage => "HOST_SHARE/CPU_USAGE", - :mem_usage => "HOST_SHARE/MEM_USAGE", - :max_mem => "HOST_SHARE/MAX_MEM", - :max_disk => "HOST_SHARE/MAX_DISK", - :max_cpu => "HOST_SHARE/MAX_CPU", - :free_mem => "HOST_SHARE/FREE_MEM", - :free_disk => "HOST_SHARE/FREE_DISK", - :free_cpu => "HOST_SHARE/FREE_CPU", - :used_disk => "HOST_SHARE/USED_DISK", - :used_mem => "HOST_SHARE/USED_MEM", - :used_cpu => "HOST_SHARE/USED_CPU" - } - - def initialize (log_file_folder,monitoring_elems=HOST_MONITORING_ELEMS) - super log_file_folder,monitoring_elems - end - - def factory(client) - HostPool.new(client) - end - - def active (host_hash) - host_hash[:state].to_i < 3 - end - - def error (host_hash) - host_hash[:state].to_i == 3 - end - - def log_snapshot - time = Time.new - puts "#{time.strftime("%Y-%m-%d %H:%M:%S")} - Hosts have been monitored\n" - STDOUT.flush - end -end diff --git a/src/sunstone/share/OneMonitor/OneMonitor.rb b/src/sunstone/share/OneMonitor/OneMonitor.rb deleted file mode 100644 index f7ada466f1..0000000000 --- a/src/sunstone/share/OneMonitor/OneMonitor.rb +++ /dev/null @@ -1,112 +0,0 @@ -# -------------------------------------------------------------------------- # -# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # -# # -# 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. # -#--------------------------------------------------------------------------- # - -ONE_LOCATION = ENV["ONE_LOCATION"] - -if !ONE_LOCATION - RUBY_LIB_LOCATION = "/usr/lib/one/ruby" -else - RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" -end - -$: << RUBY_LIB_LOCATION - -require 'OpenNebula' -require 'OneMonitorUtils' -include OpenNebula - -class OneMonitor - - OUTPUT_METHOD="CSV" - case OUTPUT_METHOD - when "CSV" then include OneMonitorCSV - end - - def initialize(log_file_folder,monitoring_elems) - # Authenticate in OpenNebula - @client = Client.new - @log_file_folder = log_file_folder - @monitoring_elems = monitoring_elems - @results = [] - reinit_global_results - end - - def snapshot - #init global results - - rc = monitor #calling the extending class method - rc = save if rc - if rc - @results = [] - reinit_global_results - log_snapshot - else - puts "Error saving new snapshot." - end - return rc - end - - def monitor - pool = factory(@client) - rc = pool.info - - if OpenNebula.is_error?(rc) - puts "Error monitoring: #{rc.message}" - return nil - end - - pool.each do | elem | - time = elem[@monitoring_elems[:time]].to_i - - hash = {} - @monitoring_elems.each do | key,value | - hash[key] = elem[value] - end - - #do not log time = 0, it causes - #graphs being drawn from 1970 - - if time > 0 - @results << hash - add_to_global(hash) - end - - @n_active += 1 if active(hash) - @n_error += 1 if error(hash) - @n_total += 1 - end - - end - - def reinit_global_results - @global_results = {} - @monitoring_elems.each do | key,value | - @global_results[key] = 0 - end - @global_results[:time] = Time.new.to_i - @n_active = @n_error = @n_total = 0 - end - - def add_to_global(hash) - hash.each do | key,value | - @global_results[key] += value.to_i - end - # time = hash[:time].to_i - puts Time.new.to_i - @global_results[:time] = Time.new.to_i - end - -end diff --git a/src/sunstone/share/OneMonitor/OneMonitorClient.rb b/src/sunstone/share/OneMonitor/OneMonitorClient.rb deleted file mode 100644 index 7f042d4d29..0000000000 --- a/src/sunstone/share/OneMonitor/OneMonitorClient.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'OneMonitorClientUtils' - -class OneMonitorClient - - INPUT_METHOD="CSV" - case INPUT_METHOD - when "CSV" then include OneMonitorCSVClient - end - - def initialize(ids, log_file_folder) - #create filenames to read - ids = [ids] unless ids.class == Array - @file_names = {} - ids.each do | id | - @file_names[id] = OneMonitorClient.full_path(log_file_folder,id) - end - return @file_names - end - - def get_multiple_data(columns,length) - result = [] - @file_names.each do | id,file_name | - result << get_data_for_id(id,columns,length) - end - return result - end - - def get_data_for_id(id, columns, length) - readOneMonitorFile(@file_names[id],columns,length) - end - - def self.full_path(folder,id) - "#{folder}/#{id}" - end -end diff --git a/src/sunstone/share/OneMonitor/OneMonitorClientUtils.rb b/src/sunstone/share/OneMonitor/OneMonitorClientUtils.rb deleted file mode 100644 index 0593b3c686..0000000000 --- a/src/sunstone/share/OneMonitor/OneMonitorClientUtils.rb +++ /dev/null @@ -1,40 +0,0 @@ -module OneMonitorCSVClient - def readOneMonitorFile(file_name,columns,length) - first_line = `head -1 #{file_name}`.chomp - - if $?.exitstatus != 0 - return [] #silently fail, cannot find this file - end - - n_lines = `wc -l #{file_name} | cut -d' ' -f 1`.to_i - if n_lines <= length.to_i - length = n_lines-1 - end - - fields = first_line.split(',') - poll_time_pos = fields.index("time") - - if !poll_time_pos - return [] #silently fail, no timestamp - end - - tail = `tail -#{length} #{file_name}` - series = [] #will hold several graphs - - columns.each do | column_name | - - graph = [] - column_pos = fields.index(column_name) - next unless column_pos - - tail.each_line do | line | - line_arr = line.delete('"').split(',') - graph << [ line_arr[poll_time_pos].to_i*1000, line_arr[column_pos].to_i ] - end - - series << graph - end - - return series - end -end diff --git a/src/sunstone/share/OneMonitor/OneMonitorUtils.rb b/src/sunstone/share/OneMonitor/OneMonitorUtils.rb deleted file mode 100644 index b512887881..0000000000 --- a/src/sunstone/share/OneMonitor/OneMonitorUtils.rb +++ /dev/null @@ -1,93 +0,0 @@ -# -------------------------------------------------------------------------- # -# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # -# # -# 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. # -#--------------------------------------------------------------------------- # - -module OneMonitorCSV - - def save - rc = save_csv - save_global_csv if rc - end - - def save_csv(separator=",") - - @results.each do | mon_hash | - id = mon_hash[:id] - log_name = "#{@log_file_folder}/#{id}" - - begin - log_file = File.new(log_name,'a') - - if !File.size?(log_name) - header = csv_header - log_file.puts(header) - end - - line = hash_to_csv(mon_hash) - log_file.puts(line) - log_file.close - rescue Exception => e - puts e.message - puts "Error writing log" - return nil - end - end - end - - def save_global_csv - begin - - global_log_file = "#{@log_file_folder}/global" - global_file = File.new(global_log_file,'a') - - if !File.size?(global_log_file) - then - header = csv_header+",active,error,total" - global_file.puts(header) - end - - csv = hash_to_csv(@global_results)+%&,"#{@n_active}","#{@n_error}","#{@n_total}"& - global_file.puts(csv) - global_file.close - return 0 - rescue Exception => e - puts e.message - puts "Error writing global results" - return nil - end - - - end - - def hash_to_csv hash,separator="," - csv_line = "" - #we need to respect the order of monitoring elems - #keys, which might not be the same in hash - @monitoring_elems.each do | key, value | - csv_line += %&"#{hash[key]}"#{separator}& - end - csv_line.chop! unless csv_line.empty? - end - - def csv_header separator="," - str = "" - @monitoring_elems.each do | key,value | - str += "#{key}," - end - #remove final separator - str.chop! unless str.empty? - end - -end diff --git a/src/sunstone/share/OneMonitor/VMMonitor.rb b/src/sunstone/share/OneMonitor/VMMonitor.rb deleted file mode 100644 index 6cea196696..0000000000 --- a/src/sunstone/share/OneMonitor/VMMonitor.rb +++ /dev/null @@ -1,54 +0,0 @@ -# -------------------------------------------------------------------------- # -# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # -# # -# 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 'OneMonitor' - -class VMMonitor < OneMonitor - - VM_MONITORING_ELEMS = { - :time => "LAST_POLL", - :id => "ID", - :name => "NAME", - :lcm_state => "LCM_STATE", - :state => "STATE", - :memory => "MEMORY", - :cpu => "CPU", - :net_tx => "NET_TX", - :net_rx => "NET_RX" - } - - def initialize (log_file_folder,monitoring_elems=VM_MONITORING_ELEMS) - super log_file_folder,monitoring_elems - end - - def factory(client) - VirtualMachinePool.new(client) - end - - def active (vm_hash) - vm_hash[:state].to_i == 3 - end - - def error (vm_hash) - vm_hash[:state].to_i == 7 - end - - def log_snapshot - time = Time.new - puts "#{time.strftime("%Y-%m-%d %H:%M:%S")} - VMs have been monitored\n" - STDOUT.flush - end -end diff --git a/src/sunstone/share/OneMonitor/runOneMonitor.rb b/src/sunstone/share/OneMonitor/runOneMonitor.rb deleted file mode 100755 index 48818a852c..0000000000 --- a/src/sunstone/share/OneMonitor/runOneMonitor.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby - -# -------------------------------------------------------------------------- # -# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # -# # -# 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. # -#--------------------------------------------------------------------------- # - -$: << File.dirname(__FILE__) - -require 'HostMonitor.rb' -require 'VMMonitor.rb' - -DEFAULT_INTERVAL= 600 #secs -DEFAULT_HOST_LOG_FOLDER = "#{ENV['ONE_LOCATION']}/logs/host/" -DEFAULT_VM_LOG_FOLDER = "#{ENV['ONE_LOCATION']}/logs/vm/" - - -#ARG0=interval, ARG1=hostfolder, ARG2=vmfolder -MONITOR_INTERVAL= ARGV[0]? ARGV[0].to_i : DEFAULT_INTERVAL #secs -HOST_LOG_FOLDER= ARGV[1]? ARGV[1]: DEFAULT_HOST_LOG_FOLDER -VM_LOG_FOLDER=ARGV[2] ? ARGV[2] : DEFAULT_VM_LOG_FOLDER - -hostm = HostMonitor.new(HOST_LOG_FOLDER) -vmm = VMMonitor.new(VM_LOG_FOLDER) - -while true do - hostm.snapshot - vmm.snapshot - sleep MONITOR_INTERVAL -end