Scott Hanselman

Penny Pinching in the Cloud: Enabling New Relic Performance Monitoring on Windows Azure Websites

May 2, '13 Comments [13] Posted in ASP.NET | Azure
Sponsored By
New Relic view of my Website

I've been looking for ways to save money running my (now 12) websites in the cloud lately. Getting insights from logs has been helpful, but I really want more details as to what my app is doing so that I might do less of it. Remember the secret of scaling an application.

Have your app do as little as possible. If you do nothing, you can scale infinitely.

I like to use tools like Glimpse to profile my apps, check database calls, and explore what's really going on. If you like application insights you may be familiar with New Relic. They are a clever system that profiles apps of all kinds, including sites ASP.NET and Azure.

I tweeted this afternoon for folks to hit my site and help me test New Relic. My lovely friends on Twitter promptly DDOS'ed my site and I respect them all the more for it.

You can actually see my site getting loaded up in this chart, and see when I scaled up within Azure and switched from Shared to Reserved. The orange instance is shared, and the blue is a NEW instances when I switched to a Reserved VM. At this point, I had enough power to weather the storm. Thanks Twitter!My site getting beaten on

How did I setup New Relic on my Web Site? New Relic happens to have an office in Portland (where I live) so I went to visit today. Coincidentally (true story) their support for Azure Web Sites has sneaked out from a closed beta to an open one recently, so I decided to hide out and see if I could add New Relic performance and application monitoring to the Hanselminutes.com podcast site.

Adding New Relic to your Azure account

Login to the Azure Portal, click on New, then Store, then New Relic from within the Store.

Adding New Relic to my Azure Portal

Pick the free plan. You can have a free plan forever, they say. It doesn't include some "bells and whistles" and a storage of large amounts of historical data, but is otherwise quite functional. Plus you get a free 14-day trial (no credit card needed) of their Pro stuff.

Screenshot (19)

Create the Add-On. They tell me the Data Center Location for New Relic doesn't matter, as you are just going to get a license key.

NOTE: If you already have a New Relic license key and existing billing relationship the you don't have to use the store or add an add-on. You can use your existing license key. However, I want my billing centralized, so any bill from New Relic will go through my Azure account. It's up to you.

Adding New Relic

Now, from within the Azure dashboard, click the new New Relic node. You can click Manage to automatically move over (and automatically single sign on) to the New Relic system dashboard. Note also the Connection Info button there. We'll need that in a minute.

New Relic within the Azure Dashboard

If you click Manage and head over to the New Relic side you'll get a Welcome Message but you won't actually SEE anything interesting until your app has successfully made its first call to their system. You can check out their .NET docs if you like. They are in flux and not entirely accurate, but they'll get there.

We need to setup our Azure Website with some environment info, then add the New Relic NuGet package.

Staying with the Azure Portal, go to the Web Site you're going to instrument, and click Configuration and setup these Configuration Values. This hooks up the New Relic production profiler to the CLR. You can keep this running all the time, and it's easy to turn off.

Add these name/value pairs:

  • COR_ENABLE_PROFILING - 1
  • COR_PROFILER -{71DA0A04-7777-4EC6-9643-7D28B46A8A41}
  • COR_PROFILER_PATH - C:\Home\site\wwwroot\newrelic\NewRelic.Profiler.dll
  • NEWRELIC_HOME - C:\Home\site\wwwroot\newrelic

Your app settings will look like this in your website config within the Azure Portal:

Azure Website Config with New Relic

Make sure you not only Save your config, but also (at least once) do a complete RESTART for New Relic to get a chance to hook in.

Add New Relic to your Web Site

Install the NewRelicWindowsAzure Nuget package using the NuGet Package Manager Console using this command:

Install-Package NewRelic.Azure.WebSites

The website for Hanselminutes.com is running on ASP.NET Web Pages and was written with WebMatrix so I used the NuGet GUI. You can tell that this package JUST got uploaded at the time of this writing as there's only 11 downloads!

New Relic NuGet Package

Install this package and it'll lay down a few DLLS and your newrelic.config file. Go into the newrelic.config and copy in the license key from Connection Info (remember that? It's in the Azure Portal and pictured above) into the  config file. Also update your Application Name to some useful value as that's going to identify your site in the New Relic dashboard.

Here I am publishing my site up to Azure. Only the NewRelic agent dlls that I just NuGet'ed in to my app are being published (and a random jpg I forgot).

Publishing the New Relic Agent to Azure

Once I deployed the site and hit it, I could see Hanselminutes appear within the New Relic system.

Hanselminutes within NewRelic

Here's some of the data I could access now! I can see an updated graph of where my time is being spent, both server side AND browser side.

Response Time

I can see which pages load fast and which don't, and exactly why.

Screenshot (45)

I can see SQL Queries and how long they took, what connections were opened...

Screenshot (48)

And deep timelines showing not just where my time was spend in my application, but also where it was spent in the .NET Framework AND CLR itself!

Screenshot (50)

And of course, I can see Stack Traces of problems with my code.

Screenshot (53)

This just scratches the surface, really, but I'm stoked I was able to get the free New Relic tier setup on Azure Websites in just about 10 minutes. I found two spots where four SQL calls could possibly be collapsed into one. I also found a common (and dumb, on my part) ArgumentNullException that I'd been missing for weeks.

I'm pretty impressed with their offering. I think the Pro Tier is a little spendy for the small indie developer, but cheap for the pro dev. I'd like to see a $5 or $10 tier for small hobbyist sites but for now, Free is going to serve me very nicely.

Now I'm going to go and instrument my other sites!

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Thursday, May 02, 2013 2:22:25 AM UTC
Just curious, how much does adding this service affect compute hours/data transfer costs for the site?
Thursday, May 02, 2013 4:16:43 AM UTC
The database stuff in the Pro version looks fantastic but the price is a bit much. My whole Azure deployment costs less. Also, the pricing is per server, I am not sure what this means. If I have a WebRole with 2 instances is this one server or two?
Craig
Thursday, May 02, 2013 4:50:49 AM UTC
Craig - unclear. But I know I can reuse the license key on all my free servers, regardless of location, so that's good.

Nick - Thanks!

Chad - Compute, my guess is very minimal. I'll ask them to comment. Egress, yes, some data out. I'll ask Azure team if it's exempt.
Thursday, May 02, 2013 1:38:52 PM UTC
Thanks Scott, especially for the quick response.
Thursday, May 02, 2013 2:04:46 PM UTC
Why is it so complicated to setup on Azure? In AppHarbor it's few clicks only. Or maybe it gives you more information when setup on Azure?
AreYouKidding?
Thursday, May 02, 2013 2:32:10 PM UTC
Awesome write up didn't even know what New Relic did!

I would agree with "AreYouKidding?" (lol) why the need for the awkward AppKeys section to be configured manually?

Otherwise this is some GOODNESS!
Thursday, May 02, 2013 2:46:43 PM UTC
No more that 2 weeks ago I've tried to install NewRelic on my web-app, only to discover that it wasn't supported.

I've started to write my own system, and now they support it. RRRRRRRRRRRR!!!!!!!!!!
Alex
Thursday, May 02, 2013 3:28:51 PM UTC
Thanks for the recommendation. I just signed up for the free (they say forever) plan and got basic monitoring for several apps and server perf setup in minutes. This is a great start for my sandbox/play-server (outside of azure for now), plus there is an iphone-app and you get a t-shirt ^^
Michael
Thursday, May 02, 2013 9:00:09 PM UTC
MetricsHub is another free add-on option that also provides great monitoring. They were also just acquired by Microsoft, so I'd imagine we'll be seeing some tighter integration there.
Fabio Cavalcante
Thursday, May 09, 2013 2:59:39 AM UTC
I think your use of sessions might be causing the 1050ms delay in System.Web.HttpRequest.BeginRequest(). When a large amount of time is spent in System.Web.HttpRequest.BeginRequest() it is commonly due to session contention.

Here is a useful link if that is the problem:

http://stackoverflow.com/questions/3629709/i-just-discovered-why-all-asp-net-websites-are-slow-and-i-am-trying-to-work-out
Greg
Friday, May 10, 2013 4:44:30 PM UTC
That looks like a great solution, lots of detail and well presented. Any recommendations for similar situations for self-hosting and reporting internally?
Alex
Monday, May 13, 2013 8:12:09 PM UTC
I try it now, but it isn't working. What a pity.
martonx
Thursday, October 24, 2013 4:29:14 AM UTC
Oh, this is nice. I tried New Relic, but at the time, they didn't support Azure Websites. I was waiting for this (but never heard it was put into effect). Now I know. Thanks.
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.