Monitoring virtual machine cost via the MyCloudSpace API

23 August 2021

Monitoring virtual machine cost via the MyCloudSpace API


One of our clever partners wanted to monitor costs of virtual machines for a mutual client. They use LogicMonitor for this client already so why not bring cost data into this same solution and have a single place to monitor and alert on their environment.

We have a few API endpoints for cost monitoring but we decided to make this heaps easier for them and create something for them to consume and do a lot of the heavy lifting on our side as well as adding some functions I think may be useful to other clients wanting to do the same thing.

Here is what I decided to include;

Hourly burn rate

a change in this would indicate that something has changed to the specification, you could alert on any change or a % difference.


Total if terminated now

In the portal you can always see how much an asset is costing you but this pricing is often based on the average monthly cost or it will show you previous months billing once that period has been finalised. Take a look at the below for example;


This shows the total for the machine if nothing changed on it at it was around for the entire month. In reality this could have been provisioned half way through the month in which case the bill for this machine would be roughly 50% of what is in the interface.

So then this figure will look at adds/moves/changes in the current period and run our billing calculations. This will increase each hour throughout the month so you can see an accumulation of cost across the month.



Some health, spec and backup information on the selected virtual machine which you could monitor and alert on specific items.

  • Health state - this will move from green to yellow/red depending on cpu and memory usage
  • Power state - is the machine on or off
  • Has Snapshot - does the VM have an active snapshot on it
  • Last backup date - either a date will be specified or it will be null (for no backup)
  • Guest information - hostname, primary ip address etc
  • Hosting site - Auckland or Christchurch

This looks like the following as an example;

Billing Line Items

A detailed item level view of items that are/will be billed in the current period. This will show all items even ones which have been "terminated" because the specification has changed, for example where a disk has been extended or cpu cores changed.

For example here is a representation of two line items showing the change in cpu cores from 1 through to 4.

You can see from the units consumed that the specification changed 256 hours into the month and this first item has a total value specified which would be the 256 hours worth of 1 virtual cpu core. It gives you the termination as a date - where is is set in the data it means it is no longer part of the current specification (it is historic)

Looking at the 4 virtual cpu core item you can see that the ended on is null meaning this item is current and part of the specification and also there is a currentSpecMonthlyCost item which shows you the cost of 4 cores if it was going to be around for the entire month. The other total field here represents what you would be billed for if the machine was terminated right now.

Hours in current month

Useful if you want to do anything with the hourly burn rate or see what percentage you are based on the billing data.

Bringing it all together

With the above in mind you can now hit the endpoint and do what you need it for. By the way if you need an API Key get in touch with and we will sort you out.

I have put together VMCost.ps1 PowerShell script located in our MyCloudSpace API Examples repository.

This is used to showcase most of the data returned, you execute it like so;

And you will get the costing output first

Following by the breakdown of the items, I have added some logic to these to show in red if the item has been terminated/is a historic record.

For those who just want to hack away at it without the script, the new endpoint is as follows

VMID is the id of the virtual machine in MyCloudSpace. Here is an example of the full output;

With that in mind, go forth and create! I would love to hear what you do with this data.


Aug 2021

Back to Articles

Other Recent Articles

Read More
Read More
Read More
Read More
Read More