Get VS CPU Usage Statistics

To view CPU usage statistics of a virtual server, use the following request:

GET  /virtual_machines/:virtual_machine_id/cpu_usage.xml
GET  /virtual_machines/:virtual_machine_id/cpu_usage.json

Define a shorter period by setting Start and End time in the API call:
GET /virtual_machines/:virtual_machine_id/vm_stats.xml?period[startdate]=YYYY-MM-DD+hh:mm:ss&period[enddate]=YYYY-MM-DD+hh:mm:ss&period[use_local_time]=1
GET /virtual_machines/:virtual_machine_id/vm_stats.json?period[startdate]=YYYY-MM-DD+hh:mm:ss&period[enddate]=YYYY-MM-DD+hh:mm:ss&period[use_local_time]=1

XML Request Example

curl -i -X GET -H 'Accept: application/xml' -H 'Content-type: application/xml' -u user:userpass --url http://onapp.test/virtual_machines/1701/cpu_usage.xml

JSON Request Example

curl -i -X GET -H 'Accept: application/json' -H 'Content-type: application/json' -u user:userpass --url http://onapp.test/virtual_machines/1701/cpu_usage.json

Where you have to specify the virtual server ID.

XML Output Example

<cpu_hourly_stats type="array">
    <cpu_time type="integer">18</cpu_time>
    <created_at type="datetime">2015-01-06T10:00:18Z</created_at>
    <stat_time type="datetime">2015-01-06T10:00:00Z</stat_time>
    <updated_at type="datetime">2015-01-06T10:00:18Z</updated_at>
    <user_id type="integer">1</user_id>
    <virtual_machine_id type="integer">1701</virtual_machine_id>


cpu_time -  use the following formula to convert CPU data received in the API output:

CPU = cpu_time /10/ 3600

Where cpu_time is data from API output.

For example:  cpu_time  = 2330, then:  2330/10/3600=0.06 (6%).

We use "cpu_time" * 10 to correct store fractional values.

created_at - the timestamp in DB when this record was created

stat_time - the particular hour for which these statistics were generated

updated_at - the time stamp in DB when this record was updated

user_id - the ID of the VS owner

virtual_machine_id - ID of the VS