Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Metrics Based Decisions @ SoftShake 2014

Johnny Graber
October 24, 2014
250

Metrics Based Decisions @ SoftShake 2014

Johnny Graber

October 24, 2014
Tweet

Transcript

  1. The World of Big Data •Every action is traced •Every

    click is analysed •Products meet exactly our needs •Privacy is dead
  2. Validated Learning 1. Specify a goal 2. Specify a metric

    3. Act to achieve the goal 4. Analyse the metric 5. Improve and try again
  3. Serilog •Structured logging for .Net •Open Source (Apache License, Version

    2.0) •Web: http://serilog.net/ •Easy to use & powerful
  4. Sinks for Serilog •Write log events to various storage formats

    •More than 20 out of the box supported •Can be extended
  5. Write JSON Log.Logger = new LoggerConfiguration() .WriteTo.Sink( new FileSink("logs.txt", new

    JsonFormatter(), null)) .CreateLogger(); { "Timestamp":"2014-10-08T21:34:25.39+02:00", "Level":"Information", "MessageTemplate":"A simple message"}
  6. Bad Log Messages  Don’t use String.Concat() and positional placeholders:

    Log.Information("{0} ordered {1}", customer, order);
  7. Whole Objects  Dump whole objects with the @ modifier:

    Log.Information("{@customer} ordered {@order}", customer, order);
  8. Seq •Search server for structured log events •Written in .Net

    •Free for a single user, plans start at 75$/5 users •Web: GetSeq.net
  9. Search for Events using •Full-text search •Directly paste error messages

    •Partial messages using Contains() •Properties of the event
  10. The Dashboard •Overview on your application •Counters to measure important

    events •Charts to display them •Queries are fully customisable
  11. Demo: Using Seq and Serilog How simple is it to

    write structured log messages? Demo
  12. Elasticsearch •End-to-end search and analytics platform •Open Source (Apache License,

    Version 2.0) •For massive amounts of structured & non-structured data •REST API
  13. Elasticsearch & Serilog // Create URI to the Elasticsearch server

    var elasticServer = new Uri("http://localhost:9200"); // Create Logger Log.Logger = new LoggerConfiguration() .WriteTo.ElasticSearch(server: elasticServer) .CreateLogger();
  14. Respecting the privacy of our users •Only collect necessary data

    •Obfuscate ID’s •Omit specific details •Work with an approximation
  15. Let’s Experiment •Given: A web application in ASP.Net •Goal: Our

    customers only use a secure operating system •Metric: #users on Windows XP
  16. Existing Data •Internal • IIS log files • Google Analytics

    • CRM •External • StatsCounter.com
  17. Collecting Additional Data •Collect the operating system at log in

    •We use • Serilog to write log messages • Seq as a sink • System.Web.Mobile.MobileCapabilities for OS detection
  18. Options to Act •Article in the newsletter •Warning message on

    the login screen •Direct mailing to the users
  19. Measure & Decide •Improve what works •Stop doing what doesn’t

    work •Decide if continuing is worth the effort •Repeat with the next assumption
  20. Demo: Using Seq and Serilog How simple is it to

    write structured log messages?
  21. Run SeqConfiguration Log.Information("A simple info message"); Log.Debug("Debug is only for

    internal use"); Log.Error("Now we have an error!"); try { var result = a / b; } catch (Exception ex) { Log.Fatal(ex, “Division {dividend}/{divisor} failed", a, b); }
  22. Build a Web Application •Create a web application with the

    VS template •Add Serilog and Seq as a sink •Configure Serilog in Application_Start
  23. Modify Application_Start (Global.asax) void Application_Start(object sender, EventArgs e) { //

    Create Logger Log.Logger = new LoggerConfiguration() .WriteTo.Seq("http://localhost:5341") .CreateLogger(); Log.Information("Start at {startup}", DateTime.Now); //Other code … }
  24. Modify web.config <browserCaps> <use var="HTTP_USER_AGENT" /> <filter> <case match="Windows NT

    6.1"> platform="Windows 7" </case> <case match="Windows XP|Windows NT 5\.1|WinNT 5\.1"> platform="Windows XP" </case> </filter> </browserCaps> </system.web>
  25. Track successful Log-in protected void LogIn(object sender, EventArgs e) {

    if (IsValid) { // Validate the user password var manager = new UserManager(); ApplicationUser user = manager.Find(UserName.Text, Password.Text); if (user != null) { IdentityHelper.SignIn(manager, user, RememberMe.Checked); LogSuccessfulLogin(user); IdentityHelper.RedirectToReturnUrl(…);
  26. Track successful Log-in private void LogSuccessfulLogin(ApplicationUser user) { // Minimalistic

    log message => only the platform is logged Log.Information("login using {os}", Context.Request.Browser.Platform); // More information at login => UserName and platform Log.Information("login by {user} using {os}", user.UserName, Context.Request.Browser.Platform); // Even more information at login => UserName, platform and session Log.Information("login by {user} using {os} in session {session}", user.UserName, Context.Request.Browser.Platform, Context.Session.SessionID); }