Thursday, May 2, 2013

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

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


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.


@shanselman Hey, you said "beat the crap out of", not "give it a little load". Two TOTALLY different things!
— Shane Milton (@Jaxidian) May 1, 2013

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 their 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






© 2013 Scott Hanselman. All rights reserved.






DIGITAL JUICE

No comments:

Post a Comment

Thank's!