1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

Make dummy drivers poll responses more random, useful to quickly check monitoring

This commit is contained in:
Carlos Martín 2012-06-27 15:48:36 +02:00
parent dbefe6f9ed
commit a4cf47f28f
2 changed files with 34 additions and 6 deletions

View File

@ -51,15 +51,17 @@ class DummyInformationManager < OpenNebulaDriver
results = "HYPERVISOR=dummy,"
results << "HOSTNAME=#{host},"
results << "TOTALCPU=800,"
results << "CPUSPEED=2.2GHz,"
used_memory = rand(16777216)
results << "TOTALMEMORY=16777216,"
results << "USEDMEMORY=0,"
results << "FREEMEMORY=16777216,"
results << "USEDMEMORY=#{used_memory},"
results << "FREEMEMORY=#{16777216-used_memory},"
results << "FREECPU=800,"
results << "USEDCPU=0"
used_cpu = rand(800)
results << "TOTALCPU=800,"
results << "USEDCPU=#{used_cpu},"
results << "FREECPU=#{800-used_cpu}"
send_message("MONITOR", RESULT[:success], number, results)
end

View File

@ -85,10 +85,36 @@ class DummyDriver < VirtualMachineDriver
end
def poll(id, drv_message)
msg = decode(drv_message)
max_memory = 256
if msg.elements["VM/TEMPLATE/MEMORY"]
max_memory = msg.elements["VM/TEMPLATE/MEMORY"].text.to_i
end
max_cpu = 100
if msg.elements["VM/TEMPLATE/CPU"]
max_cpu = msg.elements["VM/TEMPLATE/CPU"].text.to_i * 100
end
prev_nettx = 0
if msg.elements["VM/NET_TX"]
prev_nettx = msg.elements["VM/NET_TX"].text.to_i
end
prev_netrx = 0
if msg.elements["VM/NET_RX"]
prev_netrx = msg.elements["VM/NET_RX"].text.to_i
end
# monitor_info: string in the form "VAR=VAL VAR=VAL ... VAR=VAL"
# known VAR are in POLL_ATTRIBUTES. VM states VM_STATES
monitor_info = "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]} " \
"#{POLL_ATTRIBUTE[:nettx]}=12345"
"#{POLL_ATTRIBUTE[:nettx]}=#{prev_nettx+(50*rand(3))} " \
"#{POLL_ATTRIBUTE[:netrx]}=#{prev_netrx+(100*rand(4))} " \
"#{POLL_ATTRIBUTE[:usedmemory]}=#{max_memory * (rand(80)+20)/100} " \
"#{POLL_ATTRIBUTE[:usedcpu]}=#{max_cpu * (rand(95)+5)/100}"
send_message(ACTION[:poll],RESULT[:success],id,monitor_info)
end