OpenNebula Statistics API 3.0

This page contains the OpenNebula Statistics API implementation for Ruby. It has been designed for retrieving utilization information of the Cloud. This version of the API supports Virtual Machine and Host statistics.

Retrieving Resource Information

Virtual Machine

  • Method name: vm_monitoring
  • Description: Retrieve statistics for a given Virtual Machine Instance
  • Parameters
Type Data Type Description
IN Integer Virtual Machine Instance ID
IN Array An array containing the requested MONITORING RESOURCES
OUT nil/Hash Hash containing statistics information
MONITORING RESOURCES
:cpu
:memory
:net_tx
:net_rx

Host

  • Method name: host_monitoring
  • Description: Retrieve statistics for a given Host
  • Parameters
Type Data Type Description
IN Integer Host ID
IN Array An array containing the requested MONITORING RESOURCES
OUT nil/Hash Hash containing statistics information
MONITORING RESOURCES
:disk_usage
:mem_usage
:cpu_usage
:max_disk
:max_mem
:max_disk
:max_cpu
:free_disk
:free_mem
:free_cpu
:used_disk
:used_mem
:used_cpu
:rvms

Retrieving Global Information

Virtual Machine

  • Method name: vm_total
  • Description: Retrieve global statistics for Virtual Machine Instances
  • Parameters
Type Data Type Description
IN Array An array containing the requested FILTER CONDITIONS
OUT nil/Hash Hash containing global statistics information
FILTER CONDITIONS
:total
:active
:error

Host

  • Method name: host_total
  • Description: Retrieve global statistics for Hosts
  • Parameters
Type Data Type Description
IN Array An array containing the requested FILTER CONDITIONS
OUT nil/Hash Hash containing global statistics information
FILTER CONDITIONS
:total
:active
:error

Output

The Output for all the methods will be a hash containing the following values

{
  :resource   => <VM|HOST|VM_POOL|HOST_POOL>
  :id         => <nil|RESOURCE_ID>
  :monitoring => <{MONITORING_RESOURCES}|{FILTER_CODITIONS}>
}

Each monitoring resource or filter condition will contain an array of pairs [timestamp, value] that will represent values for the specified key in a range of time defined in the acct daemon configuration (WINDOW_SIZE).

Example

{
  :resource => HOST_POOL,
  :monitoring => {
    :used_cpu => [
      [1310650659,750],
      [1310650674,680],
      [1310650689,521],
      [1310650704,1083]
    ],
    :cpu_usage => [
      [1310650659,250],
      [1310650674,250],
      [1310650689,250],
      [1310650704,250]
    ],
    :max_cpu => [
      [1310650659,1600],
      [1310650674,1600],
      [1310650689,1600],
      [1310650704,1600]
    ]
  }
}

Usage

If you want to use this client to retrieve information from the Statistics Module you must have an OpenNebula site and the acct daemon properly configured and running.

The following script (test_stats.rb) will retrieve statistics of the Host 5 and the amount of Virtual Machines in a number of timestamps predefined in the acct daemon configuration (WINDOW_SIZE) until the current situation.

#!/usr/bin/env ruby
 
##############################################################################
# Required libraries
##############################################################################
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 'acct/watch_client'
require 'json'
 
# create a new Client to retrieve statistics information
watch_client = OneWatchClient::WatchClient.new
 
# Retrieve disk_usage, mem_usage and cpu_usage for Host 5
monitoring_resources = [
  :disk_usage,
  :mem_usage,
  :cpu_usage
]
 
host_stats = watch_client.host_monitoring(5, monitoring_resources)
puts JSON.pretty_generate host_stats
 
# Retrieve the number of active, error and total VMs
filter_conditions = [
  :total,
  :active,
  :error
]
 
vm_global = watch_client.vm_total(filter_conditions)
puts JSON.pretty_generate vm_global