From f5ad01b58f1dff1c41c224693ebc4b6409aa99f7 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 16 Jun 2011 17:49:09 +0200 Subject: [PATCH] Bug #686: Fix OneMonitor start/stop/logging --- src/sunstone/bin/sunstone-server | 29 ++++++++++++++++---- src/sunstone/etc/sunstone-server.conf | 5 +++- src/sunstone/share/OneMonitor/HostMonitor.rb | 6 ++++ src/sunstone/share/OneMonitor/OneMonitor.rb | 12 ++++---- src/sunstone/share/OneMonitor/VMMonitor.rb | 6 ++++ 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/sunstone/bin/sunstone-server b/src/sunstone/bin/sunstone-server index 6ecf6bb9c4..7973c20045 100755 --- a/src/sunstone/bin/sunstone-server +++ b/src/sunstone/bin/sunstone-server @@ -23,7 +23,9 @@ 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.sh + 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 @@ -32,7 +34,9 @@ else 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.sh + 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 @@ -75,7 +79,7 @@ start() touch $SUNSTONE_LOCK_FILE rackup $SUNSTONE_SERVER -s thin -p $PORT -o $HOST \ -P $SUNSTONE_PID &> $SUNSTONE_LOG & - + LASTPID=$! if [ $? -ne 0 ]; then echo "Error executing $SUNSTONE_SERVER, please check the log $SUNSTONE_LOG" exit 1 @@ -104,10 +108,21 @@ start() [[ $? -ne 0 ]] && ( echo "Error creating vm log directory"; exit 1 ) fi - $ONEMONITOR_CMD $MONITORING_INTERVAL $HOST_LOG_FOLDER $VM_LOG_FOLDER &>/dev/null & + 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" } # @@ -126,9 +141,11 @@ stop() # Remove pid files rm -f $SUNSTONE_LOCK_FILE &> /dev/null - killall $ONEMONITOR_CMD - echo "sunstone-server stopped" + + kill -KILL `cat $ONEMONITOR_PID` &> /dev/null + + echo "OneMonitor tool stopped" } case "$1" in diff --git a/src/sunstone/etc/sunstone-server.conf b/src/sunstone/etc/sunstone-server.conf index 3b1bf256fd..8855377cb8 100644 --- a/src/sunstone/etc/sunstone-server.conf +++ b/src/sunstone/etc/sunstone-server.conf @@ -4,4 +4,7 @@ PORT=9869 # VNC Configuration VNC_PROXY_BASE_PORT=29876 -NOVNC_PATH= \ No newline at end of file +NOVNC_PATH= + +# GRAPH INFO UPDATE INTERVAL (secs) +MONITORING_INTERVAL=600 diff --git a/src/sunstone/share/OneMonitor/HostMonitor.rb b/src/sunstone/share/OneMonitor/HostMonitor.rb index 59757a3d14..be0e8f37f3 100644 --- a/src/sunstone/share/OneMonitor/HostMonitor.rb +++ b/src/sunstone/share/OneMonitor/HostMonitor.rb @@ -53,4 +53,10 @@ class HostMonitor < OneMonitor 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 index 64f0707c27..f7ada466f1 100644 --- a/src/sunstone/share/OneMonitor/OneMonitor.rb +++ b/src/sunstone/share/OneMonitor/OneMonitor.rb @@ -44,10 +44,6 @@ class OneMonitor reinit_global_results end - def results - @results - end - def snapshot #init global results @@ -56,7 +52,7 @@ class OneMonitor if rc @results = [] reinit_global_results - puts "New monitoring snapshots saved." + log_snapshot else puts "Error saving new snapshot." end @@ -100,6 +96,7 @@ class OneMonitor @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 @@ -107,8 +104,9 @@ class OneMonitor hash.each do | key,value | @global_results[key] += value.to_i end - time = hash[:time].to_i - @global_results[:time] = time + # 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/VMMonitor.rb b/src/sunstone/share/OneMonitor/VMMonitor.rb index e9e0a29de3..6cea196696 100644 --- a/src/sunstone/share/OneMonitor/VMMonitor.rb +++ b/src/sunstone/share/OneMonitor/VMMonitor.rb @@ -45,4 +45,10 @@ class VMMonitor < OneMonitor 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