Showing posts with label ApplicationInsights. Show all posts
Showing posts with label ApplicationInsights. Show all posts

Reading Notes #199

ElasticDBSuggestion of the week

  • First look at Application Insights (Andrei Dzimchuk) - Excellent post. Perfect to make your idea about why and how we should use Application Insights. Nice touch to the config.

Cloud


Programming

Databases

Miscellaneous



Reading Notes #198

P1020009Cloud


Podcast

  • .NET Rocks! - Great episode very interesting discussion about the new Azure Service Fabric.

Programming


Databases



Reading Notes #178

Ballade en ski du 21 mars 2015 - 1

Suggestion of the week


Cloud


Programming


Miscellaneous



~Frank


Tons of statistics and metrics for Microsoft Azure websites (not only Asp.Net)

Your website is finally online. That great, good job. But now, you have a lot of questions: How much visits do I have? Which part of the site is mostly visited? Does the site performs well? In this post, I will show you some tools that exist in Microsoft Azure that will help you to get some answers.

Request and Error

When you create a website in Azure, you automatically got some monitoring. Go on portal.azure.com (the preview portal), and select your website.

Monitoring_2015-03-05_1540

This will be useful to see how many requests and errors you got. You could create some alerts, by clicking the "+" sign, and you would be notified by e-mail if the number of request is greater than x, over the last hour.

Analytics

The first time you will click on this section all the instruction will be given to you.
To collect end-user usage analytics about your application, insert the following script into each page you want to track. Place this code immediately before the closing </headtag, and before any other scripts. Your first data will appear automatically in just a few seconds.
To get analytics for the whole web site, in an Asp.Net MVC site, a good place will be: \Views\Shared\_Layout.cshtml.

In a Ghost blog, if you are using the default theme, the file will be /content/themes/casper/default.hbs. Otherwise, just replace "casper" by your theme name in the path.

Once your website is re-deployed, re-open the website blade and click again on the Analytics graph. And you will be able to see a lot of information: Session per browser, information on page's views, slowest pages, details on sessions, etc.


Analitics_tour


When you click on a graph, the Metrics Explorer blade will be visible. On the top of this blade, you will have many different options to customize your results. You will be able to add a chart, change the time range, add some filter and even set some alerts.


Metrics_explorer


Moreover, if you click on those Charts, tables or even on a row, you will have more details and options to fine-tune the result.


Diagnostics_Search


Application Insights

You thought it was enough? Well, Microsoft Azure still has one more tool for you, that will cover in this post: Application Insights. With this one, you will be able to see the health of your application by adding some tests, custom events, logs, errors, etc.
Adding Application Insights to your Asp.Net website, can easily be done via Visual Studio, like I explained in a previous post.

Since Azure is compatible with many different languages, chances are that you are using one of those. Let say you are running a node.js Ghost blog, how could you add Application Insights? By using website extensions. To add an extension you could use the Kudu interface. This interface is easy to access. In a browser, type the URL of the website but inject "scm" between the name of the application and the azurewebsites.net. Something like http://mybookmanager.scm.azurewebsites.net/


From_Kudu_Console2015-03-01_2044


Once you are in the Kudu interface, click on the tab Site Extensions, then section Gallery. Add the Application Insights Extension.
It's also possible to add a website extension using the website blade.


From_portal_2015-03-01_2101


This will gives you a lot of information already, but to add more customs metric in .Net by sure to add the Application Insights SDK to your porject. In node.js use the applicationinsights package from npm,

~Frank Boucher



References




Four Simple Tips to Improve your Asp.Net MVC Project

When it's time to do the re-factoring of a solution, it's always a good idea to clean the code before doing any re-factoring. In this post, I will share with you simple but very efficient ways to improve your solution.

1- Forget the magic string


By default in Asp.Net MVC magic strings are used every where.
return View("Index");
or
@Html.ActionLink("Delete Dinner", "Delete", "Dinners", new { id = Model.DinnerID }, null)

Nothing bad here, but nothing will tell you that to did a typo, or that the method name as changed. This is where T4MVC will become a great tool do add to all your project.

To add it a simple Nuget command is enough: Install-Package T4MVC. By doing this a T4 file (T4MVC.tt) will be added to your project that will generates a number of files. These generated files will simplify your life and gives you the opportunity to code using strongly type.

Here are few transformations:
// Before ----------------
  return View("Index");

// After with T4MVC
  return View(Views.Index);
An action link in a view.
// Before ----------------
  @Html.ActionLink("Delete Product", "Delete", "Products", new { id = Model.ProductID }, null)

// After with T4MVC
  @Html.ActionLink("Delete Product", MVC.Products.Delete(Model.ProductID))

An Ajax call.
// Before ----------------
<%= Ajax.ActionLink( "RSVP for this event",
                 "Register", "RSVP",
                 new { id=Model.DinnerID }, 
                 new AjaxOptions { UpdateTargetId="rsvpmsg", OnSuccess="AnimateRSVPMessage" }) %>

// After with T4MVC
<%= Ajax.ActionLink( "RSVP for this event",
                 MVC.RSVP.Register(Model.DinnerID),
                 new AjaxOptions { UpdateTargetId="rsvpmsg", OnSuccess="AnimateRSVPMessage" }) %>

A redirection.
// Before ----------------
return RedirectToAction("Details", new { id = product.ProductID });

// After with T4MVC
return RedirectToAction(MVC.Products.Details(product.ProductID));

When writing the code, it gives you intellisense where you normally would not have any. At compile time, it validates all the code so no typo or other misspelling errors are present.

2- Clean your views


You know all those "@using" on the top of each views that we copy over and over... It's time to remove them. The way to do it is by moving them to the web.config file in the "Views" folder.

web.config location

So you can move the namespaces used globally
@using Microsoft.Security.Application
@using System.Globalization;

by including them to this section:
<system.web.webPages.razor>
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />

      <add namespace="Microsoft.Security.Application" />
      <add namespace="System.Globalization" />

    </namespaces>
  </pages>
</system.web.webPages.razor>

3- Don't lose time debugging


To many people are losing time debugging their application or web site. Start using Glimpse right away! This will provide information in real time across all layers of your application from the UI to the server and database side. Perfect to know everything that happen on a click of a button: javascript validation, controller code and even the query in the database.







Install it in ten seconds with the Nuget command manager and pick the version you need.

PM> Install-Package Glimpse



Glimpse is secure and is configured to be accessible only from localhost by default. But don't trust me and try it by yourself, or go check this one minute Glimpse Heads Up Display youtube video.

4- Start monitoring your website health and usage


Move your website on Microsoft Azure and use the Application Insights. This will gives you the opportunity to monitor that availability, performance and usage of your live application.

Add Application Insights


To add it you got many possibilities, one of them from Visual Studio 2013, just right-click on the project and select Add Application Insights Telemetry, and voilĂ !

Now you just need to run or deploy the website and after few minutes or so you will have plenty of information, graphs waiting for you in the Azure Portal.



Informations



You will find a lot of information about Application Insights on the Microsoft Azure


Wrapping up

I hope it will help you, thanks for reading. Any comments, suggestions and/or questions are welcome.

~ Frank Boucher


References