Monitor your M365 Backups using the MyCloudSpace API
Every now and then we like to put out a new example of what could be achieved by our MyCloudSpace API. We have touched on Virtual machine tasks like snapshot and power operations in the past. More recently we looked at the new cost monitor endpoints.
But, we have not had a look at monitoring your M365 Backups. I have put together two examples (which could be combined of course) that you can do the following with:
- Tracking total storage consumption + licensed users
- Tracking Job status and recent job history
The storage and licensing consumption on in particular would be a good candidate to poll on a regular basis and send the data to an InfluxDB and put a Grafana dashboard on top so you can visualise your utilisation.
Both examples are in the public MyCloudSpace git repository under powershell/apiKey and written in PowerShell. You can adapt this to any language as it is just making https calls to our REST api.
Before you get started
You will need
- API key, reach out to us if you need one
- The VBO tenant ID, see below
To get the tenant id, log into MyCloudSpace and navigate to your deployed tenancy and view the tenant. Then grab the number in the address bar after .../o365tenant/ represented as 12345 in the yellow box below.
In each of the scripts you pass the tenant ID as a parameter of the script named vboID
You also need to update lines ~28/29 with your user and api key values
M365TrackUsage.ps1
This pulls down the total storage consumed in gb and the total licensed users.
A note for the licensed users, this is the "active" users on your tenancy - there will likely be other users in your tenancy but we only track active users from a billing perspective.
.\M365TrackUsage.ps1 -vboId 12345
You can see this then returns
- The tenant identifier (in green), useful if you are tracking more than one tenant backup and storing in a common InfluxDB or similar you can tag accordingly
- The user license count
- The storage consumption (updated hourly) in gigabytes
M365JobSessionReport.ps1
This looks at the tenancy, iterates each of the backup jobs, shows the status. If there are sessions then will show you the last few session runs and how much data was processed as well as the job duration.
.\M365JobSessionReport.ps1 -vboId 12345
You can see this then returns
- The tenant identifier (in green), useful if you are tracking more than one tenant backup and storing in a common InfluxDB or similar you can tag accordingly
- The job name highlighted with the (1), there will be ~4 jobs per tenancy one for each OneDrive, Sharepoint, Teams and Exchange Online. You could use this job name to tag data in Influx also.
- Highlighted by point (2) is some session statistics like run duration, status and total transferred