1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

Feature #650: Completed Sunstone server support to read and send log files data

This commit is contained in:
Hector Sanjuan 2011-05-20 15:41:50 +02:00 committed by Ruben S. Montero
parent ef9755ef32
commit e63cd9a0a2
2 changed files with 71 additions and 1 deletions

View File

@ -262,6 +262,62 @@ class SunstoneServer
return [200, nil]
end
############################################################################
#
############################################################################
def get_log(resource,id,config,request)
log_file_prefix = case resource
when "vm","VM"
config[:host_log_file]
when "host","HOST"
config[:vm_log_file]
end
log_file = "#{log_file_prefix}_#{id}.csv"
request_json = parse_json(request,"monitor")
history_length = request_json[:history_length]
element = request_json[:element]
first_line = `head -1 #{log_file}`
if $?.exitstatus != 0
then
error = Error.new("Cannot open log file")
return [500, error.to_json]
end
fields = first_line.split(',')
poll_time_pos = fields.index("time")
resource_pos = fields.index(element)
id_pos = fields.index("id")
graph = []
tail = `tail -#{history_length} #{log_file}`
tail.each_line do | line |
line_arr = line.delete('"').split(',')
if (line_arr[id_pos].to_i == id.to_i)
then
graph << [ line_arr[poll_time_pos], line_arr[resource_pos] ]
end
end
return graph.to_json
end
############################################################################
#
############################################################################
############################################################################
#
############################################################################
private

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
@ -155,6 +156,20 @@ get '/vm/:id/log' do
@SunstoneServer.get_vm_log(params[:id])
end
##############################################################################
# Logs
##############################################################################
get '/:resource/monitor' do
end
get '/:resource/:id/monitor' do
get_log(params[:resource],params[:id],settings.config,request.body.read)
end
##############################################################################
# GET Pool information
##############################################################################
@ -239,4 +254,3 @@ end
post '/:resource/:id/action' do
@SunstoneServer.perform_action(params[:resource], params[:id], request.body.read)
end