Using the Azure Monitor REST API from Google Apps Script
This post describes how to get metrics (in this case average response time) from an Azure App Service into a Google Sheet. I’m doing this so I can go from the sheet to a Data Studio dashboard. I already have a report in Data Studio that pulls from Ads, Analytics and other sources. I’d rather spend hours adding Azure there than be forced to have one more tab open. You might have different reasons. Read on.
- Create a Google Sheet and give it a memorable name. Rename the first sheet to AvgResponseTime and put ‘Date’ in A1 and ‘Average Response Time’ in B1.
- Create a script (Script editor from the Tools menu) and give that a good name as well.
- In the script editor pick Libraries from the Resources menu. Enter 1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF which is the Google OAuth library, pick the latest version and click Save.
- Select Project properties from the File menu and make a note of the Script ID.
- Log into your Azure Console and then go to https://resources.azure.com/. You are looking for a metricdefinitions node for the resource that you want to monitor. In my case it’s subscriptions / MyName Subscription / resourceGroups / providers / Microsoft.Web / sites / MySite / metricdefintions. Browse through this list to find the id of the metric you’re interested in. For me it’s AverageResponseTime. Finding this was the hardest part. Microsoft’s documentation for resourceUri is literally ‘The identifier of the resource.’ Why even bother Microsoft? Make a note of the id and remove the ‘metricDefinitions/AverageResponseTime’ from the end, because of course the ID isn’t quite right for some reason. Mine looks something like this: /subscriptions/mylongid/resourceGroups/mysomethingResourceGroup/providers/Microsoft.Web/sites/mysiteid
- Go back to the Azure Console and open Azure Active Directory. Select App registrations under Manage and create a New registration. Time to come up with another name. You probably want ‘Accounts in this organizational directory only’. The redirect URL is https://script.google.com/macros/d/SCRIPTID/usercallback - replace SCRIPTID with the Script ID you made a note of in step 4.
- Click the View API permissions button, then Add a permission and then pick Azure Service Management. I’m using Delegated permissions and the user_impersonation permission. Then click Grant admin consent for Default Directory.
- Go to Certificates & secrets (under manage) and create a new client secret. Make a careful note of it.
- Go to Authentication (under Manage), check Access tokens under Implicit grant and then click Save at the top of the page.
- Go to Overview and make a note of your Application (client) ID and Directory (tennant) ID.
- You are getting close! Go to the script editor (from step 2) and paste in the code at the bottom of this post. There are four variables to enter at the top of the script. ClientID and TennantID are from step 10. ClientSecret is from step 8. ResourceID is from step 5. Save the script.
- Reload the spreadsheet (back from step 1). You should get an Azure Monitor menu item. Choose Authorize from this menu. Google will ask you to authorize the script, do this for the Google account you’re using. Choose Authorize again, this time a sidebar will appear with a link. Follow the link and authorize against Azure (if you’re logged in this might just go directly to success). If you get authorization errors in the future run this step again. If that does help use Reset Settings and then try again.
- You should be ready to get data. Choose Fetch Data from the Azure Monitor menu. If this doesn’t work check through steps 1-12 carefully again!
- Last step - automate. Go back to the script editor. Choose Current project’s triggers from the Edit menu. Add a trigger (the small blue button hidden at the bottom right of the screen - not everything needs a floating action button Google!) to run fetchData daily at some reasonable time.
More Google Apps Script Projects
- Get an email when your security camera sees something new (Apps Script + Cloud Vision)
- Get an email if your site stops being mobile friendly
- Export Google Fit Daily Steps, Weight and Distance to a Google Sheet
- Email Alerts for new Referers in Google Analytics using Apps Script
- Animation of a year of Global Cloud Cover
- Control LIFX WiFi light bulbs from Google Apps Script
- How to backup Google Photos to Google Drive automatically after July 2019 with Apps Script
- Using the Todoist API to set a due date on the Alexa integration to-do list (with Apps Script)
- Automate Google PageSpeed Insights and Core Web Vitals Logging with Apps Script
- Monitor page index status with Google Sheets, Apps Script and the Google Search Console API
Book reviews for March 2020
The Unconsoled by Kazuo Ishiguro
5/5
Mostly read this in a deserted nightclub on the roof of a hotel in India with a warm but dirty breeze and some trippy chilled out music. It's the only way to read this strange book. Anywhere else I might not have enjoyed it quite a much after the first few chapters, but in the setting it was transcendental.
Related Posts
You Might Also Like
ITHCWY Newsletter for March 2020
More Bangalore: Timelapse featuring Tipu Sultan's Summer Palace, Lalbagh Botanical Garden, KR flower market, Bangalore Palace and Cubbon Park.
Coastal: an abstract timelapse of the California coast.
Jesse Wegman has written a book, Let the People Pick the President: The Case for Abolishing the Electoral College (review) and a NYT op-ed on switching to a more rational way of electing the President. If you support this idea I have a page on the topic with four concrete things you can do to help.
Hike to Kirby Cove Beach (Marin Headlands near San Francisco).
Tool to backup locked files on Windows 10 - great for XCOPY backups or just grabbing a locked file.
Previously:
- 2019: Age and Life Expectancy Weighted Voting
- 2018: Facebook shouldn't own your social graph
- 2017: Book reviews for February 2017
Related Posts
You Might Also Like
Great Blue Heron
Several photos of Great Blue Herons at Crissy Field in San Francisco.
Updated 2020-05-04 19:32:
Updated 2023-10-01 23:40:
Great Blue Heron and two turtles at Stow Lake in the Golden Gate Park
Updates
Great Blue Heron at Crissy Field
Related Posts
You Might Also Like
Backup locked files on Windows 10: Volume Shadow Copy Update
The Volume Shadow Copy Service (VSS) can be used to mount a copy of a drive in a crash consistent state (like you just unplugged your computer) as a different drive letter. My shadow task command line tool makes it easy to do this. Here's an example:
ShadowTask64 C V test.bat
This creates a shadow copy of the C: drive, mounts it as V: and then runs test.bat. When test.bat completes the shadow V: drive is removed.
What can you do with this?
The simple case is grabbing a copy of a locked file. In this case test.bat could just run pause and then grab the file you need from V:.
It's also a great way to run a backup. In this case the batch file can run XCOPY (to a network share or portable drive) and you'll get all your files including anything locked like running executables or Outlook PST files.
Grab the latest from GitHub: abfo/shadow/releases. You'll find a ZIP file and source code if you want to use/extend this. There are 32 and 64-bit binaries - you need to use the right one for your computer and you also need to run the tool with administrative privileges. This only works with NTFS drives.
Related Posts
- Do useful things with the volume shadow copy service (VSS)
- WiX Tricks for Screen Savers
- Folder Insights
You Might Also Like
- Catfood: WebCamSaver and PdfScan
- Fixing dropped wireless connection for Linksys E4200
- ISS over Wales
Vernal (Spring) Equinox 2020
Spring starts right now in the Northern Hemisphere (Autumn if you find yourself south of the Equator). Rendered in Catfood Earth.
Related Posts
You Might Also Like
Firmware
"Please be careful not to update while in riding on vehicles, such as trains, or in environments where 2.4 GHz band radio waves such as Wi-Fi, microwave ovens, cordless phones and many other radio waves are intermingled."
It looks like I need to travel to the United States National Radio Quiet Zone in West Virginia to update the firmware in my headphones, and I don't think that's on the cards for several months so I hope the update isn't important.
Nice touch that they gave an example of a vehicle though, that really helps.
Maybe use a checksum Sony?
Related Posts
You Might Also Like
- Monitor page index status with Google Sheets, Apps Script and the Google Search Console API
- Pacifica
- Support SHIELD–a small measure of patent sanity
Kirby Cove
A short two mile out and back from the Battery Spencer parking area on Conzelman Road to Kirby Cove.
The Marin Headlands have had a bit of a traffic management change recently so you need to go through the tunnel to get in and Conzelman Road is now one way back to highway 101. The advantage is that there is way more parking then there used to be. I think I've only ever managed to park near Battery Spencer once in 20 years.
The walk is my least favorite profile, downhill to start and uphill on the way back and also not a loop. It's worth it though because it's short and Kirby Cove beach is quiet and has wonderful views of San Francisco through the Golden Gate Bridge. You can also visit Battery Wagner and Battery Kirby on the way back up.
Hike starts at: 37.829459, -122.48401. View in Google Earth.
Related Posts
You Might Also Like
(Hike Map)
News: We May Be Living in a Simulation, but the Truth Still Matters
We May Be Living in a Simulation, but the Truth Still Matters
I like this article because Kara Swisher actually gets the history right. Read my series on this starting with Can I move to a Better Simulation Please?.
Related Posts
- Can I move to a Better Simulation Please?
- Have we Already Proved that the Simulation Hypothesis is False?
- Was there ever any doubt that I would eventually write this post?
You Might Also Like
Coastal
An abstract timelapse of the California coast.
The sequences were shot over about six hours using a Sony RX100V, f5.6, 1 second exposure, ND3 filter and ISO 80 to around 250 depending on the light. Most of the frames are from the Marin headlands, one sequence is from Sutro Baths in San Francisco.
Post production used Lightroom and LRTimelapse. I skipped LRTimelapse rendering and wrote a custom application to mirror the frames (for this video mirroring is left/right top/bottom and for one sequence both). I then used ffmpeg to render each mirrored sequence and Premiere Elements to edit them together. Finally I added music with Filmstro.
If anyone is interested in the mirroring application post a comment below and I'll tidy it up a bit and release it.
This timelapse is absolutely inspired by the main title sequence for Bosch on Amazon Video.